Submission #644420

#TimeUsernameProblemLanguageResultExecution timeMemory
644420Do_you_copyGift (IZhO18_nicegift)C++17
100 / 100
1327 ms108240 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second using namespace std; using ll = long long; using pii = pair <int, int>; #define pb push_back const int maxN = 1e6 + 10; const int maxOP = 3e6; int n, k; int a[maxN]; priority_queue <pii> PQ; vector <vector <int>> e; void Init(){ cin >> n >> k; ll sum = 0; for (int i = 1; i <= n; ++i){ cin >> a[i]; sum += a[i]; PQ.push({a[i], i}); } if (sum % k || PQ.top().fi > sum / k){ cout << -1; return; } while (sum){ vector <int> pos; for (int j = 0; j < k; ++j){ pos.pb(PQ.top().se); PQ.pop(); } int add = a[pos.back()]; if (!PQ.empty()) add = min(add, sum / k - PQ.top().fi); sum -= add * k; e.pb({add}); for (int j = 0; j < k; ++j){ e.back().pb(pos[j]); a[pos[j]] -= add; PQ.push({a[pos[j]], pos[j]}); } } cout << e.size() << "\n"; for (auto &i: e){ for (auto &j: i) cout << j << " "; cout << "\n"; } } signed main() { Init(); }
#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...