网易的<塔>那道题,一种不一样的思路;AC
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n,m;
while (cin >> n>>m)
{
int cnt = 1;
vector<pair<int, int>> higher;
vector<pair<int, int>> data;
while (n--)
{
int high;
cin >> high;
pair<int,int> hh;
hh.first = high;
hh.second = cnt;
cnt++;
higher.push_back(hh);
}
sort(higher.begin(), higher.end());
int count = 0;
while (m--)
{
if ((higher.front().first == higher.back().first)||
((higher.front().first+1) == higher.back().first))
break;
pair<int, int> dd;
higher.back().first--;
higher.front().first++;
dd.first = higher.back().second;
dd.second = higher.front().second;
data.push_back(dd);
sort(higher.begin(), higher.end());
count++;
}
cout << higher.back().first - higher.front().first
<< " " << count << endl;
for (auto i : data)
{
cout << i.first << " " << i.second << endl;
}
}
return 0;
}
#网易#
查看7道真题和解析