# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
511148 | 2022-01-15T09:18:48 Z | Mazaalai | Gift (IZhO18_nicegift) | C++17 | 2 ms | 588 KB |
#include <bits/stdc++.h> #define pb push_back #define ff first #define ss second #define LLA(x) x.rbegin(),x.rend() #define print(x) for(auto el:x)cout<<el<<' ';cout<<"\n"; #define printPII(x) for(auto [a,b]:x)cout<<a<<","<<b<<' ';cout<<'\n'; using namespace std; using ll = long long; using PII = pair <ll, int>; ll n, k, onePick = 1; bool impossible; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); cin >> n >> k; vector <vector <int> > ans; vector <ll> ansW; set <PII> bfs; ll sum = 0, val; int id; for (int i = 1; i <= n; i++) { ll x; cin >> x; sum += x; bfs.insert({x, i}); } bfs.insert({0, 0}); ll packs = sum / k; if (sum % k != 0 || bfs.rbegin()->ff > packs) { cout << "-1\n"; return 0; } while(packs > 0) { vector <PII> add; for (int i = 0; i < k; i++) { auto it = --bfs.end(); tie(val, id) = *it; bfs.erase(it); add.pb({val, id}); } ll pick = min(add.back().ff, packs-((--bfs.end())->ff)); packs -= pick; vector <int> cur; for (int i = 0; i < k; i++) { tie(val, id) = add.back(); add.pop_back(); val -= pick; cur.pb(id); bfs.insert({val, id}); } ansW.pb(pick); ans.pb(cur); } cout << ans.size() << '\n'; for (auto el : ans) {print(el);} }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 588 KB | Execution killed with signal 8 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 588 KB | Execution killed with signal 8 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 588 KB | Execution killed with signal 8 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 588 KB | Execution killed with signal 8 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 588 KB | Execution killed with signal 8 |
2 | Halted | 0 ms | 0 KB | - |