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.

67 lines
1.5 KiB

2 years ago
#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;
}