Example
input
8
2
2 3
3
1 2 3
4
1 2 3 4
3
0 0 2
2
6 2
3
0 0 2
5
8 2 0 1 1
5
0 1 0 0 6
output
2
1 2
1 2
3
1 3
2 3
2 3
5
1 3
2 4
2 4
3 4
3 4
0
2
1 2
1 2
0
4
1 2
1 5
1 4
1 2
1
5 2
解析:
贪心,每次选择两个剩余次数最多的人,并且交谈一次。
此处只能交谈一次,并不能完全令一个人为0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int t,n,a[N];
int main(){scanf("%d",&t);while(t--){scanf("%d",&n);priority_queue<pair<int,int>>q;for(int i=1;i<=n;i++){scanf("%d",&a[i]);if(a[i]>0) q.push({a[i],i});}vector<pair<int,int>>v;while(q.size()>1){pair<int,int>a=q.top();q.pop();pair<int,int>b=q.top();q.pop();v.push_back({a.second,b.second});if(a.first-1) q.push({a.first-1,a.second});if(b.first-1) q.push({b.first-1,b.second});}printf("%d\n",v.size());for(int i=0;i<v.size();i++) printf("%d %d\n",v[i].first,v[i].second);}return 0;
}