Submission #335288

#TimeUsernameProblemLanguageResultExecution timeMemory
335288limabeansGift (IZhO18_nicegift)C++17
7 / 100
2101 ms524292 KiB
#include <bits/stdc++.h> using namespace std; template<typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl using ll = long long; const int maxn = 1e6 + 5; ll n,k; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>k; assert(k==2); priority_queue<pair<ll,int>> pq; ll sum=0; for (int i=1; i<=n; i++) { ll x; cin>>x; sum += x; pq.push({x,i}); } if (sum%k) out(-1); vector<vector<int>> w; while (pq.size()) { auto cur = pq.top(); pq.pop(); auto cur2 = pq.top(); pq.pop(); w.push_back({cur.second,cur2.second}); cur.first--; cur2.first--; if (cur.first) { pq.push(cur); } if (cur2.first) { pq.push(cur2); } } cout<<w.size()<<"\n"; for (auto p: w) { cout<<1<<" "<<p[0]<<" "<<p[1]<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...