# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
721030 | 2023-04-10T08:24:28 Z | cig32 | Gift (IZhO18_nicegift) | C++17 | 849 ms | 119584 KB |
#include "bits/stdc++.h" #define int long long using namespace std; const int MAXN = 1e5 + 10; void solve(int tc) { int n, k; cin >> n >> k; priority_queue<pair<int,int> > pq; int a[n+1]; for(int i=1; i<=n; i++) { cin >> a[i]; pq.push({a[i], i}); } if(k == n) { for(int i=1; i<n; i++){ if(a[i] != a[i+1]) { cout << "-1\n"; return; } } cout << "1\n"; cout << a[1]; for(int i=1; i<=n; i++) cout << " " << i; cout << '\n'; return; } int lim = 3000000 / k; vector<vector<int> > ops; while(lim--) { while(pq.size() && pq.top().first == 0) pq.pop(); if(pq.empty()) break; if(pq.size() < k) { cout << "-1\n"; return; } int mn = 1e18; stack<pair<int, int> > st; vector<int> lol; for(int i=0; i<k; i++) { st.push(pq.top()); mn = min(mn, pq.top().first); lol.push_back(pq.top().second); pq.pop(); } int cmp = 0; if(pq.size()) cmp = pq.top().first; mn = max(1ll, mn - cmp); while(st.size()) { if(st.top().first != mn) { pq.push({st.top().first - mn, st.top().second}); } st.pop(); } for(int x: lol) { a[x] -= mn; } lol.push_back(mn); ops.push_back(lol); } for(int i=1; i<=n; i++) { if(a[i] != 0) { cout << "-1\n"; return; } } cout << ops.size() << "\n"; for(vector<int> v: ops) { cout << v.back(); for(int i=0; i<k; i++) cout << " " << v[i]; cout << "\n"; } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t=1; //cin>>t; for(int i=1; i<=t; i++)solve(i); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | n=4 |
2 | Correct | 0 ms | 212 KB | n=3 |
3 | Correct | 0 ms | 212 KB | n=3 |
4 | Correct | 1 ms | 316 KB | n=4 |
5 | Correct | 0 ms | 212 KB | n=4 |
6 | Correct | 0 ms | 212 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | n=4 |
2 | Correct | 0 ms | 212 KB | n=3 |
3 | Correct | 0 ms | 212 KB | n=3 |
4 | Correct | 1 ms | 316 KB | n=4 |
5 | Correct | 0 ms | 212 KB | n=4 |
6 | Correct | 0 ms | 212 KB | n=2 |
7 | Correct | 1 ms | 212 KB | n=5 |
8 | Correct | 1 ms | 340 KB | n=8 |
9 | Correct | 8 ms | 1148 KB | n=14 |
10 | Correct | 4 ms | 704 KB | n=11 |
11 | Correct | 24 ms | 3736 KB | n=50000 |
12 | Correct | 33 ms | 4832 KB | n=50000 |
13 | Correct | 22 ms | 2828 KB | n=10 |
14 | Correct | 33 ms | 2928 KB | n=685 |
15 | Correct | 29 ms | 3212 KB | n=623 |
16 | Correct | 19 ms | 1880 KB | n=973 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | n=4 |
2 | Correct | 0 ms | 212 KB | n=3 |
3 | Correct | 0 ms | 212 KB | n=3 |
4 | Correct | 1 ms | 316 KB | n=4 |
5 | Correct | 0 ms | 212 KB | n=4 |
6 | Correct | 0 ms | 212 KB | n=2 |
7 | Correct | 1 ms | 212 KB | n=5 |
8 | Correct | 1 ms | 340 KB | n=8 |
9 | Correct | 8 ms | 1148 KB | n=14 |
10 | Correct | 4 ms | 704 KB | n=11 |
11 | Correct | 24 ms | 3736 KB | n=50000 |
12 | Correct | 33 ms | 4832 KB | n=50000 |
13 | Correct | 22 ms | 2828 KB | n=10 |
14 | Correct | 33 ms | 2928 KB | n=685 |
15 | Correct | 29 ms | 3212 KB | n=623 |
16 | Correct | 19 ms | 1880 KB | n=973 |
17 | Correct | 24 ms | 3000 KB | n=989 |
18 | Correct | 11 ms | 1236 KB | n=563 |
19 | Correct | 17 ms | 1748 KB | n=592 |
20 | Correct | 21 ms | 1620 KB | n=938 |
21 | Correct | 14 ms | 1340 KB | n=747 |
22 | Correct | 18 ms | 1484 KB | n=991 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 849 ms | 119584 KB | Jury has the answer but participant has not |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | n=4 |
2 | Correct | 0 ms | 212 KB | n=3 |
3 | Correct | 0 ms | 212 KB | n=3 |
4 | Correct | 1 ms | 316 KB | n=4 |
5 | Correct | 0 ms | 212 KB | n=4 |
6 | Correct | 0 ms | 212 KB | n=2 |
7 | Correct | 1 ms | 212 KB | n=5 |
8 | Correct | 1 ms | 340 KB | n=8 |
9 | Correct | 8 ms | 1148 KB | n=14 |
10 | Correct | 4 ms | 704 KB | n=11 |
11 | Correct | 24 ms | 3736 KB | n=50000 |
12 | Correct | 33 ms | 4832 KB | n=50000 |
13 | Correct | 22 ms | 2828 KB | n=10 |
14 | Correct | 33 ms | 2928 KB | n=685 |
15 | Correct | 29 ms | 3212 KB | n=623 |
16 | Correct | 19 ms | 1880 KB | n=973 |
17 | Correct | 24 ms | 3000 KB | n=989 |
18 | Correct | 11 ms | 1236 KB | n=563 |
19 | Correct | 17 ms | 1748 KB | n=592 |
20 | Correct | 21 ms | 1620 KB | n=938 |
21 | Correct | 14 ms | 1340 KB | n=747 |
22 | Correct | 18 ms | 1484 KB | n=991 |
23 | Incorrect | 849 ms | 119584 KB | Jury has the answer but participant has not |
24 | Halted | 0 ms | 0 KB | - |