Submission #57610

#TimeUsernameProblemLanguageResultExecution timeMemory
57610hugo_pmGift (IZhO18_nicegift)C++14
100 / 100
1603 ms115736 KiB
#include <bits/stdc++.h> #pragma GCC diagnostic ignored "-Wunused-result" #define int long long using namespace std; const int maxVerrous = 1000*1000; int nbVerrous, tailleOperation; int reqUnlock[maxVerrous]; int cur[maxVerrous]; priority_queue<pair<int, int>> prq; signed main() { scanf("%lld%lld", &nbVerrous, &tailleOperation); int som = 0, mx = 0; for (int indVerrou = 0; indVerrou < nbVerrous; ++indVerrou) { scanf("%lld", &reqUnlock[indVerrou]); som += reqUnlock[indVerrou]; mx = max(mx, reqUnlock[indVerrou]); prq.push({reqUnlock[indVerrou], indVerrou}); } if (som % tailleOperation != 0 || mx > som / tailleOperation) { printf("-1\n"); return 0; } vector<vector<int>> operations; operations.reserve(100*1000); vector<int> curOp(tailleOperation + 1); int red = som / tailleOperation; while (! prq.empty()) { int nbRestants = prq.size(); if (nbRestants < tailleOperation) { printf("-1\n"); return 0; } stack<int> remise; int x = LLONG_MAX; for (int indPris = 1; indPris <= tailleOperation; ++indPris) { auto e = prq.top(); prq.pop(); curOp[indPris] = e.second; x = min(x, e.first); remise.push(e.second); } if (! prq.empty()) { x = min(x, red - prq.top().first); } curOp[0] = x-1; red -= x; operations.push_back(curOp); while (! remise.empty()) { int ld = remise.top(); cur[ld] += x; if (reqUnlock[ld] - cur[ld] != 0) { prq.push({reqUnlock[ld] - cur[ld], ld}); } remise.pop(); } } printf("%lld\n", (int)(operations.size())); for (auto op : operations) { for (int choisi : op) { printf("%lld ", choisi+1); } printf("\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...