You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
int a [ 110 ] = { 0 } ;
int n , k , s = INT32_MAX ;
vector < pair < int , int > > v1 ;
//准备返回两个参数值.就是判断数组a中, 哪个索引号的值最大, 最大值是多少
void maxA ( int & inx , int & num ) {
num = INT32_MIN ;
for ( int i = 1 ; i < = n ; i + + ) {
if ( a [ i ] > num ) {
num = a [ i ] ;
inx = i ;
}
}
}
//准备返回两个参数值.就是判断数组a中, 哪个索引号的值最小, 最小值是多少
void minA ( int & inx , int & num ) {
num = INT32_MAX ;
for ( int i = 1 ; i < = n ; i + + ) {
if ( a [ i ] < num ) {
num = a [ i ] ;
inx = i ;
}
}
}
int main ( ) {
//输入+输出重定向
freopen ( " ../1268.txt " , " r " , stdin ) ;
cin > > n > > k ;
for ( int i = 1 ; i < = n ; i + + ) {
cin > > a [ i ] ;
}
//计算,从最大的中拿出1个, 放到最小的里面去
int m = 0 ;
while ( m < = k ) {
int maxIndex , maxNumber , minIndex , minNumber ;
maxA ( maxIndex , maxNumber ) ;
minA ( minIndex , minNumber ) ;
a [ maxIndex ] - - ;
a [ minIndex ] + + ;
if ( a [ maxIndex ] - a [ minIndex ] < s ) {
s = a [ maxIndex ] - a [ minIndex ] ;
v1 . push_back ( { maxIndex , minIndex } ) ;
} else {
break ;
}
m + + ;
}
cout < < s < < " " < < m < < endl ;
for ( int i = 0 ; i < v1 . size ( ) ; + + i ) {
cout < < v1 [ i ] . first < < " " < < v1 [ i ] . second < < endl ;
}
//关闭文件
fclose ( stdin ) ;
return 0 ;
}