#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define MN 1207171
using namespace std;
using ll = long long;
ll n, k, A[MN];
set<pair<ll, ll> > S;
vector<pair<ll, vector<ll>>> O;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
ll sum = 0;
for(ll i = 1; i <= n; ++i)
cin >> A[i], S.insert({A[i], i}), sum += A[i];
if(S.rbegin()->first > sum / k || sum % k) {
cout << "-1\n";
return 0;
}
ll vmin, suma_ramasa, delta;
vector<ll> PU;
while(!S.empty()) {
suma_ramasa = sum;
for(ll i = 1; i <= k; ++i)
PU.push_back(S.rbegin()->second), suma_ramasa -= S.rbegin()->first, S.erase(*S.rbegin());
if(!S.empty())
delta = min(A[PU.back()], sum / k - S.rbegin()->first);
else delta = A[PU.back()];
O.push_back({delta, PU});
for(auto it : PU){
A[it] -= delta;
sum -= delta;
if(A[it])
S.insert({A[it], it});
}
PU.clear();
}
cout << O.size() << "\n";
for(auto [c, v] : O) {
cout << c << " ";
for(auto it : v)
cout << it << " ";
cout << "\n";
}
return 0;
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:24:8: warning: unused variable 'vmin' [-Wunused-variable]
24 | ll vmin, suma_ramasa, delta;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
1 ms |
324 KB |
n=3 |
4 |
Correct |
1 ms |
320 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
1 ms |
320 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
1 ms |
324 KB |
n=3 |
4 |
Correct |
1 ms |
320 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
1 ms |
320 KB |
n=2 |
7 |
Correct |
1 ms |
204 KB |
n=5 |
8 |
Correct |
1 ms |
204 KB |
n=8 |
9 |
Correct |
0 ms |
320 KB |
n=14 |
10 |
Correct |
1 ms |
204 KB |
n=11 |
11 |
Correct |
27 ms |
5432 KB |
n=50000 |
12 |
Correct |
35 ms |
5192 KB |
n=50000 |
13 |
Correct |
1 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
1 ms |
324 KB |
n=3 |
4 |
Correct |
1 ms |
320 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
1 ms |
320 KB |
n=2 |
7 |
Correct |
1 ms |
204 KB |
n=5 |
8 |
Correct |
1 ms |
204 KB |
n=8 |
9 |
Correct |
0 ms |
320 KB |
n=14 |
10 |
Correct |
1 ms |
204 KB |
n=11 |
11 |
Correct |
27 ms |
5432 KB |
n=50000 |
12 |
Correct |
35 ms |
5192 KB |
n=50000 |
13 |
Correct |
1 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 |
Correct |
1 ms |
316 KB |
n=989 |
18 |
Correct |
1 ms |
320 KB |
n=563 |
19 |
Correct |
1 ms |
320 KB |
n=592 |
20 |
Correct |
1 ms |
316 KB |
n=938 |
21 |
Correct |
1 ms |
332 KB |
n=747 |
22 |
Correct |
1 ms |
332 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
739 ms |
114596 KB |
n=1000000 |
2 |
Correct |
431 ms |
64308 KB |
n=666666 |
3 |
Correct |
253 ms |
37888 KB |
n=400000 |
4 |
Correct |
174 ms |
28260 KB |
n=285714 |
5 |
Correct |
15 ms |
2128 KB |
n=20000 |
6 |
Correct |
101 ms |
16944 KB |
n=181818 |
7 |
Correct |
5 ms |
1228 KB |
n=10000 |
8 |
Correct |
4 ms |
840 KB |
n=6666 |
9 |
Correct |
2 ms |
588 KB |
n=4000 |
10 |
Correct |
5 ms |
624 KB |
n=2857 |
11 |
Correct |
1 ms |
460 KB |
n=2000 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
n=4 |
2 |
Correct |
0 ms |
204 KB |
n=3 |
3 |
Correct |
1 ms |
324 KB |
n=3 |
4 |
Correct |
1 ms |
320 KB |
n=4 |
5 |
Correct |
0 ms |
204 KB |
n=4 |
6 |
Correct |
1 ms |
320 KB |
n=2 |
7 |
Correct |
1 ms |
204 KB |
n=5 |
8 |
Correct |
1 ms |
204 KB |
n=8 |
9 |
Correct |
0 ms |
320 KB |
n=14 |
10 |
Correct |
1 ms |
204 KB |
n=11 |
11 |
Correct |
27 ms |
5432 KB |
n=50000 |
12 |
Correct |
35 ms |
5192 KB |
n=50000 |
13 |
Correct |
1 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 |
Correct |
1 ms |
316 KB |
n=989 |
18 |
Correct |
1 ms |
320 KB |
n=563 |
19 |
Correct |
1 ms |
320 KB |
n=592 |
20 |
Correct |
1 ms |
316 KB |
n=938 |
21 |
Correct |
1 ms |
332 KB |
n=747 |
22 |
Correct |
1 ms |
332 KB |
n=991 |
23 |
Correct |
739 ms |
114596 KB |
n=1000000 |
24 |
Correct |
431 ms |
64308 KB |
n=666666 |
25 |
Correct |
253 ms |
37888 KB |
n=400000 |
26 |
Correct |
174 ms |
28260 KB |
n=285714 |
27 |
Correct |
15 ms |
2128 KB |
n=20000 |
28 |
Correct |
101 ms |
16944 KB |
n=181818 |
29 |
Correct |
5 ms |
1228 KB |
n=10000 |
30 |
Correct |
4 ms |
840 KB |
n=6666 |
31 |
Correct |
2 ms |
588 KB |
n=4000 |
32 |
Correct |
5 ms |
624 KB |
n=2857 |
33 |
Correct |
1 ms |
460 KB |
n=2000 |
34 |
Correct |
19 ms |
3208 KB |
n=23514 |
35 |
Correct |
19 ms |
3272 KB |
n=23514 |
36 |
Correct |
1 ms |
448 KB |
n=940 |
37 |
Correct |
1 ms |
204 KB |
n=2 |
38 |
Correct |
56 ms |
9132 KB |
n=100000 |
39 |
Correct |
66 ms |
9108 KB |
n=100000 |
40 |
Correct |
0 ms |
204 KB |
n=10 |
41 |
Correct |
1 ms |
332 KB |
n=100 |
42 |
Correct |
5 ms |
460 KB |
n=1000 |
43 |
Correct |
890 ms |
116256 KB |
n=1000000 |
44 |
Execution timed out |
2036 ms |
117008 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |