# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1060519 | 2024-08-15T16:38:24 Z | Jarif_Rahman | Gift (IZhO18_nicegift) | C++17 | 1915 ms | 524288 KB |
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<ll> A(n); for(ll &x: A) cin >> x; vector<pair<ll, vector<int>>> ans; priority_queue<pair<ll, int>> pq; for(int i = 0; i < n; i++) pq.push({A[i], i}); ll X = 0; for(ll x: A) X+=x; if(X%k != 0 || *max_element(A.begin(), A.end()) > X/k){ cout << "-1\n"; exit(0); } X/=k; while(pq.size() >= k){ vector<int> cur; for(int i = 0; i < k; i++) cur.push_back(pq.top().second), pq.pop(); ll lim = 0; if(!pq.empty()) lim = pq.top().first; for(int x: cur) A[x]-=X-lim; ans.push_back({X-lim, cur}); X = lim; /*if(ans.size() > int(3e6)){ cout << "-1\n"; exit(0); }*/ for(int x: cur) if(A[x]) pq.push({A[x], x}); } if(pq.size() != 0){ cout << "-1\n"; exit(0); } cout << ans.size() << "\n"; for(auto [x, v]: ans){ cout << x << " "; for(int i: v) cout << i+1 << " "; cout << "\n"; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | n=4 |
2 | Correct | 0 ms | 348 KB | n=3 |
3 | Correct | 0 ms | 348 KB | n=3 |
4 | Correct | 0 ms | 348 KB | n=4 |
5 | Correct | 0 ms | 348 KB | n=4 |
6 | Correct | 0 ms | 348 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | n=4 |
2 | Correct | 0 ms | 348 KB | n=3 |
3 | Correct | 0 ms | 348 KB | n=3 |
4 | Correct | 0 ms | 348 KB | n=4 |
5 | Correct | 0 ms | 348 KB | n=4 |
6 | Correct | 0 ms | 348 KB | n=2 |
7 | Runtime error | 963 ms | 524288 KB | Execution killed with signal 9 |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | n=4 |
2 | Correct | 0 ms | 348 KB | n=3 |
3 | Correct | 0 ms | 348 KB | n=3 |
4 | Correct | 0 ms | 348 KB | n=4 |
5 | Correct | 0 ms | 348 KB | n=4 |
6 | Correct | 0 ms | 348 KB | n=2 |
7 | Runtime error | 963 ms | 524288 KB | Execution killed with signal 9 |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1915 ms | 524288 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | n=4 |
2 | Correct | 0 ms | 348 KB | n=3 |
3 | Correct | 0 ms | 348 KB | n=3 |
4 | Correct | 0 ms | 348 KB | n=4 |
5 | Correct | 0 ms | 348 KB | n=4 |
6 | Correct | 0 ms | 348 KB | n=2 |
7 | Runtime error | 963 ms | 524288 KB | Execution killed with signal 9 |
8 | Halted | 0 ms | 0 KB | - |