# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
495337 | 2021-12-18T13:19:24 Z | Ziel | Gift (IZhO18_nicegift) | C++17 | 1248 ms | 524292 KB |
/** * LES GREATEABLES BRO TEAM **/ #include <bits/stdc++.h> using namespace std; using ll = long long; #define sz(x) (int)x.size() const bool FLAG = false; void setIO(const string &f = ""); #define int ll const int N = 2e6 + 4; ll n, k, a[N]; void solve() { cin >> n >> k; ll sum = 0, mx = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; mx = max(mx, a[i]); sum += a[i]; } if (sum % k != 0 || mx > sum / k) { cout << -1; return; } sum /= k; ll cur_sum = 0; deque<pair<int, int>> s[k + 1]; int id = 1; for (int i = 1; i <= n; i++) { if (cur_sum + a[i] <= sum) { cur_sum += a[i]; s[id].push_back({a[i], i}); if (cur_sum == sum) { id++; cur_sum = 0; } } else if (cur_sum + a[i] > sum) { int y = cur_sum + a[i] - sum, x = a[i] - y; s[id].push_back({x, i}); id++; s[id].push_back({y, i}); cur_sum = 0; } } vector<vector<int>> ans; while (true) { int mx = 1000000000; for (int i = 1; i <= k; i++) { mx = min(mx, s[i].front().first); } if (!mx) break; vector<int> cur; cur.push_back(mx); for (int i = 1; i <= k; i++) { cur.push_back(s[i].front().second); s[i].front().first -= mx; if (!s[i].front().first) { s[i].pop_front(); } } ans.push_back(cur); for (int i = 1; i <= k; i++) { if (!sz(s[i])) { break; } } } for (int i = 1; i <= k; i++) { if (sz(s[i])) { cout << -1; return; } } cout << sz(ans) << '\n'; for (auto x: ans) { for (auto y: x) cout << y << ' '; cout << '\n'; } } signed main() { setIO(); int tt = 1; if (FLAG) { cin >> tt; } while (tt--) { solve(); } return 0; } void setIO(const string &f) { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen((f + ".in").c_str(), "r")) { freopen((f + ".in").c_str(), "r", stdin); freopen((f + ".out").c_str(), "w", stdout); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | n=4 |
2 | Correct | 1 ms | 204 KB | n=3 |
3 | Correct | 0 ms | 204 KB | n=3 |
4 | Correct | 1 ms | 204 KB | n=4 |
5 | Correct | 0 ms | 204 KB | n=4 |
6 | Correct | 0 ms | 204 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | n=4 |
2 | Correct | 1 ms | 204 KB | n=3 |
3 | Correct | 0 ms | 204 KB | n=3 |
4 | Correct | 1 ms | 204 KB | n=4 |
5 | Correct | 0 ms | 204 KB | n=4 |
6 | Correct | 0 ms | 204 KB | n=2 |
7 | Correct | 0 ms | 204 KB | n=5 |
8 | Correct | 0 ms | 204 KB | n=8 |
9 | Correct | 0 ms | 204 KB | n=14 |
10 | Correct | 1 ms | 320 KB | n=11 |
11 | Correct | 22 ms | 3820 KB | n=50000 |
12 | Correct | 21 ms | 3648 KB | n=50000 |
13 | Correct | 0 ms | 204 KB | n=10 |
14 | Correct | 1 ms | 332 KB | n=685 |
15 | Correct | 1 ms | 332 KB | n=623 |
16 | Correct | 1 ms | 332 KB | n=973 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | n=4 |
2 | Correct | 1 ms | 204 KB | n=3 |
3 | Correct | 0 ms | 204 KB | n=3 |
4 | Correct | 1 ms | 204 KB | n=4 |
5 | Correct | 0 ms | 204 KB | n=4 |
6 | Correct | 0 ms | 204 KB | n=2 |
7 | Correct | 0 ms | 204 KB | n=5 |
8 | Correct | 0 ms | 204 KB | n=8 |
9 | Correct | 0 ms | 204 KB | n=14 |
10 | Correct | 1 ms | 320 KB | n=11 |
11 | Correct | 22 ms | 3820 KB | n=50000 |
12 | Correct | 21 ms | 3648 KB | n=50000 |
13 | Correct | 0 ms | 204 KB | n=10 |
14 | Correct | 1 ms | 332 KB | n=685 |
15 | Correct | 1 ms | 332 KB | n=623 |
16 | Correct | 1 ms | 332 KB | n=973 |
17 | Incorrect | 1 ms | 332 KB | Jury has the answer but participant has not |
18 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1248 ms | 524292 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 332 KB | n=4 |
2 | Correct | 1 ms | 204 KB | n=3 |
3 | Correct | 0 ms | 204 KB | n=3 |
4 | Correct | 1 ms | 204 KB | n=4 |
5 | Correct | 0 ms | 204 KB | n=4 |
6 | Correct | 0 ms | 204 KB | n=2 |
7 | Correct | 0 ms | 204 KB | n=5 |
8 | Correct | 0 ms | 204 KB | n=8 |
9 | Correct | 0 ms | 204 KB | n=14 |
10 | Correct | 1 ms | 320 KB | n=11 |
11 | Correct | 22 ms | 3820 KB | n=50000 |
12 | Correct | 21 ms | 3648 KB | n=50000 |
13 | Correct | 0 ms | 204 KB | n=10 |
14 | Correct | 1 ms | 332 KB | n=685 |
15 | Correct | 1 ms | 332 KB | n=623 |
16 | Correct | 1 ms | 332 KB | n=973 |
17 | Incorrect | 1 ms | 332 KB | Jury has the answer but participant has not |
18 | Halted | 0 ms | 0 KB | - |