Submission #378658

#TimeUsernameProblemLanguageResultExecution timeMemory
378658rk42745417Gift (IZhO18_nicegift)C++17
18 / 100
2070 ms116792 KiB
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ull = uint64_t; using uint = uint32_t; using ld = long double; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const ll LINF = 2e18; const double EPS = 1e-9; #define EMT ios::sync_with_stdio(0); cin.tie(0); signed main() { EMT int n, k; cin >> n >> k; vector<int> arr(n); priority_queue<pair<int, int>> pq; for(int i = 0; i < n; i++) cin >> arr[i], pq.push({arr[i], i}); vector<tuple<int, int, int>> ans; auto get = [&]() { if(pq.empty()) return -1; int w = pq.top().second; pq.pop(); return w; }; while(!pq.empty()) { int x = get(), y = get(); if(y < 0) return cout << "-1\n", 0; ans.push_back({1, x, y}); arr[x]--; arr[y]--; if(arr[x]) pq.push({arr[x], x}); if(arr[y]) pq.push({arr[y], y}); } cout << ans.size() << '\n'; for(const auto &[v, x, y] : ans) cout << v << ' ' << x + 1 << ' ' << y + 1 << '\n'; }
#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...