#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
ll N, K, A[1000006], sum, acc[1000006], id[1000006];
vector<pair<ll, pll>> v;
vector<ll> t;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> N >> K;
for (int i = 1; i <= N; i++)
{
cin >> A[i];
sum += A[i];
}
if (sum % K)
{
cout << -1 << '\n';
return 0;
}
for (int i = 1; i <= N; i++)
if (A[i] > sum / K)
{
cout << -1 << '\n';
return 0;
}
int cur = 1;
for (int i = 1; i <= N; i++)
{
if (A[i] >= sum / K - acc[cur])
{
v.emplace_back(make_pair(acc[cur], pll(cur, i)));
A[i] -= sum / K - acc[cur];
cur++;
}
if (A[i])
v.emplace_back(make_pair(acc[cur], pll(cur, i)));
acc[cur] += A[i];
}
v.emplace_back(make_pair(sum / K, pll(0, 0)));
for (auto [a, p] : v)
t.emplace_back(a);
sort(v.begin(), v.end());
sort(t.begin(), t.end());
t.resize(unique(t.begin(), t.end()) - t.begin());
cout << t.size() - 1 << '\n';
int vdx = 0;
for (int i = 1; i < t.size(); i++)
{
cout << t[i] - t[i - 1];
while (vdx < v.size() && v[vdx].F <= t[i - 1])
{
id[v[vdx].S.F] = v[vdx].S.S;
vdx++;
}
for (int i = 1; i <= K; i++)
cout << ' ' << id[i];
cout << '\n';
}
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:47:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
47 | for (auto [a, p] : v)
| ^
nicegift.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i = 1; i < t.size(); i++)
| ~~^~~~~~~~~~
nicegift.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | while (vdx < v.size() && v[vdx].F <= t[i - 1])
| ~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=4 |
2 |
Correct |
0 ms |
340 KB |
n=3 |
3 |
Correct |
0 ms |
212 KB |
n=3 |
4 |
Correct |
0 ms |
340 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 |
0 ms |
340 KB |
n=4 |
2 |
Correct |
0 ms |
340 KB |
n=3 |
3 |
Correct |
0 ms |
212 KB |
n=3 |
4 |
Correct |
0 ms |
340 KB |
n=4 |
5 |
Correct |
0 ms |
212 KB |
n=4 |
6 |
Correct |
0 ms |
212 KB |
n=2 |
7 |
Correct |
0 ms |
340 KB |
n=5 |
8 |
Correct |
0 ms |
212 KB |
n=8 |
9 |
Correct |
0 ms |
340 KB |
n=14 |
10 |
Correct |
1 ms |
340 KB |
n=11 |
11 |
Correct |
16 ms |
3388 KB |
n=50000 |
12 |
Correct |
17 ms |
3384 KB |
n=50000 |
13 |
Correct |
1 ms |
340 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
0 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=4 |
2 |
Correct |
0 ms |
340 KB |
n=3 |
3 |
Correct |
0 ms |
212 KB |
n=3 |
4 |
Correct |
0 ms |
340 KB |
n=4 |
5 |
Correct |
0 ms |
212 KB |
n=4 |
6 |
Correct |
0 ms |
212 KB |
n=2 |
7 |
Correct |
0 ms |
340 KB |
n=5 |
8 |
Correct |
0 ms |
212 KB |
n=8 |
9 |
Correct |
0 ms |
340 KB |
n=14 |
10 |
Correct |
1 ms |
340 KB |
n=11 |
11 |
Correct |
16 ms |
3388 KB |
n=50000 |
12 |
Correct |
17 ms |
3384 KB |
n=50000 |
13 |
Correct |
1 ms |
340 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
0 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
17 |
Correct |
2 ms |
340 KB |
n=989 |
18 |
Correct |
1 ms |
340 KB |
n=563 |
19 |
Correct |
1 ms |
340 KB |
n=592 |
20 |
Correct |
2 ms |
440 KB |
n=938 |
21 |
Correct |
1 ms |
340 KB |
n=747 |
22 |
Correct |
2 ms |
340 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
495 ms |
73824 KB |
n=1000000 |
2 |
Correct |
238 ms |
51496 KB |
n=666666 |
3 |
Correct |
137 ms |
29340 KB |
n=400000 |
4 |
Correct |
232 ms |
36480 KB |
n=285714 |
5 |
Correct |
8 ms |
1740 KB |
n=20000 |
6 |
Correct |
193 ms |
27176 KB |
n=181818 |
7 |
Correct |
6 ms |
1104 KB |
n=10000 |
8 |
Correct |
29 ms |
2312 KB |
n=6666 |
9 |
Correct |
2 ms |
604 KB |
n=4000 |
10 |
Correct |
123 ms |
9908 KB |
n=2857 |
11 |
Correct |
1 ms |
468 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n=4 |
2 |
Correct |
0 ms |
340 KB |
n=3 |
3 |
Correct |
0 ms |
212 KB |
n=3 |
4 |
Correct |
0 ms |
340 KB |
n=4 |
5 |
Correct |
0 ms |
212 KB |
n=4 |
6 |
Correct |
0 ms |
212 KB |
n=2 |
7 |
Correct |
0 ms |
340 KB |
n=5 |
8 |
Correct |
0 ms |
212 KB |
n=8 |
9 |
Correct |
0 ms |
340 KB |
n=14 |
10 |
Correct |
1 ms |
340 KB |
n=11 |
11 |
Correct |
16 ms |
3388 KB |
n=50000 |
12 |
Correct |
17 ms |
3384 KB |
n=50000 |
13 |
Correct |
1 ms |
340 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
0 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
17 |
Correct |
2 ms |
340 KB |
n=989 |
18 |
Correct |
1 ms |
340 KB |
n=563 |
19 |
Correct |
1 ms |
340 KB |
n=592 |
20 |
Correct |
2 ms |
440 KB |
n=938 |
21 |
Correct |
1 ms |
340 KB |
n=747 |
22 |
Correct |
2 ms |
340 KB |
n=991 |
23 |
Correct |
495 ms |
73824 KB |
n=1000000 |
24 |
Correct |
238 ms |
51496 KB |
n=666666 |
25 |
Correct |
137 ms |
29340 KB |
n=400000 |
26 |
Correct |
232 ms |
36480 KB |
n=285714 |
27 |
Correct |
8 ms |
1740 KB |
n=20000 |
28 |
Correct |
193 ms |
27176 KB |
n=181818 |
29 |
Correct |
6 ms |
1104 KB |
n=10000 |
30 |
Correct |
29 ms |
2312 KB |
n=6666 |
31 |
Correct |
2 ms |
604 KB |
n=4000 |
32 |
Correct |
123 ms |
9908 KB |
n=2857 |
33 |
Correct |
1 ms |
468 KB |
n=2000 |
34 |
Correct |
11 ms |
2012 KB |
n=23514 |
35 |
Correct |
11 ms |
1996 KB |
n=23514 |
36 |
Correct |
1 ms |
340 KB |
n=940 |
37 |
Correct |
1 ms |
340 KB |
n=2 |
38 |
Correct |
55 ms |
8832 KB |
n=100000 |
39 |
Correct |
55 ms |
8868 KB |
n=100000 |
40 |
Correct |
1 ms |
340 KB |
n=10 |
41 |
Correct |
1 ms |
340 KB |
n=100 |
42 |
Correct |
4 ms |
596 KB |
n=1000 |
43 |
Correct |
390 ms |
75172 KB |
n=1000000 |
44 |
Correct |
622 ms |
85712 KB |
n=1000000 |
45 |
Correct |
340 ms |
64568 KB |
n=666666 |
46 |
Correct |
265 ms |
43032 KB |
n=400000 |
47 |
Correct |
151 ms |
9656 KB |
n=2336 |
48 |
Correct |
231 ms |
36552 KB |
n=285714 |
49 |
Correct |
201 ms |
27124 KB |
n=181818 |
50 |
Correct |
154 ms |
14652 KB |
n=40000 |
51 |
Correct |
126 ms |
12624 KB |
n=20000 |
52 |
Correct |
134 ms |
10828 KB |
n=10000 |
53 |
Correct |
115 ms |
10512 KB |
n=6666 |
54 |
Correct |
119 ms |
10052 KB |
n=4000 |
55 |
Correct |
114 ms |
9844 KB |
n=2857 |
56 |
Correct |
114 ms |
9264 KB |
n=2000 |