# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
511144 | 2022-01-15T09:16:08 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, ll>; 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 <ll> > ans; set <PII> bfs; ll sum = 0, val, id, dbg = 0; 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 <ll> cur(1, pick); for (int i = 0; i < k; i++) { tie(val, id) = add.back(); add.pop_back(); val -= pick; cur.pb(id); bfs.insert({val, id}); } 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 | 532 KB | Execution killed with signal 8 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 532 KB | Execution killed with signal 8 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 532 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 | 532 KB | Execution killed with signal 8 |
2 | Halted | 0 ms | 0 KB | - |