# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
347081 | 2021-01-11T17:07:30 Z | andrii | Gift (IZhO18_nicegift) | C++14 | 2000 ms | 514124 KB |
// -- // #include <bits/stdc++.h> #define pll pair<ll, ll> #define x first #define y second using namespace std; typedef long long ll; const ll N = 1e6+228; const ll inf = 0x3fff3fff3fff3fff; pll a[N]; vector<pair<ll, vector<ll>>> qrs; ll us[N]; signed main(){ cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0); ll n, k, sai=0; cin >> n >> k; for(ll i = 0;i<n;i++){ cin >> a[i].x; a[i].y=i; sai+=a[i].x; } sort(a, a+n, greater<pll>()); if(sai%k) return cout<<-1, 0; set<pll, greater<pll>> allow; for(ll i = 0;i<n;i++) allow.insert({a[i].x, i}); for(;!allow.empty();){ if(allow.size()<k) return cout<<-1, 0; vector<ll> qk; ll mv= inf; for(ll i = 0;i<k;i++){ qk.push_back(allow.begin()->second); mv=allow.begin()->first; allow.erase(allow.begin()); } if(!allow.empty()) mv=mv-allow.begin()->first; for(auto i : qk){ us[i]+=mv; if(us[i]<a[i].x) allow.insert({a[i].x-us[i], i}); } qrs.push_back({mv, qk}); } cout<<qrs.size()<<'\n'; for(auto i :qrs){ cout<<i.x<<' '; for(auto j : i.y) cout<<a[j].y+1<<' '; cout<<'\n'; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2094 ms | 514124 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2094 ms | 514124 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2094 ms | 514124 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2102 ms | 275720 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2094 ms | 514124 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |