纯暴力.....
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> using namespace std; int n,k; struct TA { int x,id; }ta[200]; bool cmp(TA a,TA b) { return a.x<b.x; } vector<int> ans; int main() { scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) { int x; scanf("%d",&x); ta[i].x=x; ta[i].id=i; } while(k--) { sort(ta+1,ta+1+n,cmp); int diff=ta[n].x-ta[1].x; if(diff==0) break; else { ta[n].x--; ta[1].x++; ans.push_back(ta[n].id); ans.push_back(ta[1].id); } } sort(ta+1,ta+1+n,cmp); int diff=ta[n].x-ta[1].x; int sz=ans.size(); printf("%d %d ",diff,sz/2); for(int i=0;i<sz;i+=2) { printf("%d %d ",ans[i],ans[i+1]); } return 0; }