#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll C = 5e4;
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});
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-1;
lim = min(lim, C);
ll mn = 1e18+5;
for(int x: cur) mn = min(mn, A[x]-lim);
for(int x: cur) A[x]-=mn;
ans.push_back({mn, cur});
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
nicegift.cpp: In function 'int main()':
nicegift.cpp:17:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
17 | while(pq.size() >= k){
| ~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 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 |
Correct |
0 ms |
348 KB |
n=5 |
8 |
Correct |
0 ms |
348 KB |
n=8 |
9 |
Correct |
3 ms |
1068 KB |
n=14 |
10 |
Correct |
2 ms |
860 KB |
n=11 |
11 |
Correct |
16 ms |
4056 KB |
n=50000 |
12 |
Correct |
20 ms |
4816 KB |
n=50000 |
13 |
Correct |
9 ms |
2128 KB |
n=10 |
14 |
Correct |
17 ms |
3404 KB |
n=685 |
15 |
Correct |
19 ms |
3660 KB |
n=623 |
16 |
Correct |
10 ms |
2124 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
Correct |
0 ms |
348 KB |
n=5 |
8 |
Correct |
0 ms |
348 KB |
n=8 |
9 |
Correct |
3 ms |
1068 KB |
n=14 |
10 |
Correct |
2 ms |
860 KB |
n=11 |
11 |
Correct |
16 ms |
4056 KB |
n=50000 |
12 |
Correct |
20 ms |
4816 KB |
n=50000 |
13 |
Correct |
9 ms |
2128 KB |
n=10 |
14 |
Correct |
17 ms |
3404 KB |
n=685 |
15 |
Correct |
19 ms |
3660 KB |
n=623 |
16 |
Correct |
10 ms |
2124 KB |
n=973 |
17 |
Correct |
18 ms |
2896 KB |
n=989 |
18 |
Correct |
8 ms |
984 KB |
n=563 |
19 |
Correct |
13 ms |
1396 KB |
n=592 |
20 |
Correct |
15 ms |
1488 KB |
n=938 |
21 |
Correct |
10 ms |
1240 KB |
n=747 |
22 |
Correct |
14 ms |
1240 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
821 ms |
220732 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
Correct |
0 ms |
348 KB |
n=5 |
8 |
Correct |
0 ms |
348 KB |
n=8 |
9 |
Correct |
3 ms |
1068 KB |
n=14 |
10 |
Correct |
2 ms |
860 KB |
n=11 |
11 |
Correct |
16 ms |
4056 KB |
n=50000 |
12 |
Correct |
20 ms |
4816 KB |
n=50000 |
13 |
Correct |
9 ms |
2128 KB |
n=10 |
14 |
Correct |
17 ms |
3404 KB |
n=685 |
15 |
Correct |
19 ms |
3660 KB |
n=623 |
16 |
Correct |
10 ms |
2124 KB |
n=973 |
17 |
Correct |
18 ms |
2896 KB |
n=989 |
18 |
Correct |
8 ms |
984 KB |
n=563 |
19 |
Correct |
13 ms |
1396 KB |
n=592 |
20 |
Correct |
15 ms |
1488 KB |
n=938 |
21 |
Correct |
10 ms |
1240 KB |
n=747 |
22 |
Correct |
14 ms |
1240 KB |
n=991 |
23 |
Incorrect |
821 ms |
220732 KB |
Jury has the answer but participant has not |
24 |
Halted |
0 ms |
0 KB |
- |