|

General

# Author Problem Lang Verdict Time Memory Sent Judged
130623552 Practice:
lemeraemail
1579D - 35 GNU C++17 Wrong answer on test 2 15 ms 3640 KB 2021-10-03 10:11:48 2021-10-03 10:11:48

→ Source
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#define mod 1000000007
using namespace std;
typedef long long ll;
int main (){
int t;cin>>t;
while(t--){
vector<pair<ll,ll>> v;
priority_queue<pair<ll,ll>> pq;
ll n;cin>>n;
for(int i=0;i<n;i++){
ll temp;cin>>temp;
if(temp == 0)
continue;
pq.push({temp,i+1});
}
ll ct=0;
while(pq.size()>1){
auto a = pq.top();
pq.pop();
auto b = pq.top();
pq.pop();
if(a.first == b.first){
ct+=a.first;
for(int i=0;i<a.first;i++){
v.push_back({a.second,b.second});
}
}else{
ll temp = b.first;
ct+=temp;
pq.push({a.first-b.first,a.second});
for(int i=0;i<temp;i++){
v.push_back({a.second,b.second});
}
}
}
cout<<ct<<"\n";
for(int i=0;i<v.size();i++){
cout<<v[i].first<<" "<<v[i].second<<"\n";
}
}
}


?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
?
?
?