#include <bits/stdc++.h>
using namespace std;
vector < pair <long long int, pair<long long int, long long int> > > s;
set <long long int> m;
long long int a [1000010];
vector <long long int> ans [3000010];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, k; cin >> n >> k; long long int gr=0; long long int sum=0;
for (int i=0; i<n; i++){
long long int x; cin >> x; a[i]=x; sum+=a[i];
}
for (int i=0; i<n; i++){
long long int x=a[i];
s.push_back ({(gr)%(sum/k), {i, 0}}); gr+=x;
//cout << gr << endl;
if (gr%(sum/k)==0) s.push_back ({sum/k, {i, 1}});
else s.push_back ({(gr)%(sum/k), {i, 1}});
if ((gr-x)%(sum/k)>gr%(sum/k) && gr%(sum/k)!=0){
s.push_back ({0, {i, 0}});
s.push_back ({sum/k, {i, 1}});
}
}
if (gr%k!=0){
cout << -1; return 0;
}
long long int ind=0;
for (int i=0; i<n; i++) if (a[i]>gr/k) {cout << -1; return 0;};
sort (s.begin(), s.end()); long long int pr=0;
for (int i=0; i<s.size(); i++){
long long int x=s [i].first; long long int y=s[i].second.first; long long int t=s[i].second.second;
//cout << x << " " << y << " " << t << endl;
if (t==0){
if (x-pr!=0){
ans [ind].push_back (x-pr);
for (auto e:m){
ans [ind].push_back (e+1);
}
ind++;
}
m.insert (y);
}
else{
if (x-pr!=0){
ans [ind].push_back (x-pr);
for (auto e:m){
ans [ind].push_back (e+1);
}
ind++;
}
m.erase (y);
}
pr=x;
}
cout << ind << endl;
for (int i=0; i<ind; i++){
for (int j=0; j<ans [i].size(); j++) cout << ans [i][j] << " ";
cout << endl;
}
return 0;
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:31:17: 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]
31 | for (int i=0; i<s.size(); i++){
| ~^~~~~~~~~
nicegift.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int j=0; j<ans [i].size(); j++) cout << ans [i][j] << " ";
| ~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
70732 KB |
n=4 |
2 |
Correct |
33 ms |
70712 KB |
n=3 |
3 |
Correct |
34 ms |
70700 KB |
n=3 |
4 |
Correct |
34 ms |
70708 KB |
n=4 |
5 |
Correct |
33 ms |
70676 KB |
n=4 |
6 |
Correct |
32 ms |
70760 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
70732 KB |
n=4 |
2 |
Correct |
33 ms |
70712 KB |
n=3 |
3 |
Correct |
34 ms |
70700 KB |
n=3 |
4 |
Correct |
34 ms |
70708 KB |
n=4 |
5 |
Correct |
33 ms |
70676 KB |
n=4 |
6 |
Correct |
32 ms |
70760 KB |
n=2 |
7 |
Correct |
36 ms |
70728 KB |
n=5 |
8 |
Correct |
32 ms |
70728 KB |
n=8 |
9 |
Correct |
33 ms |
70772 KB |
n=14 |
10 |
Correct |
33 ms |
70716 KB |
n=11 |
11 |
Correct |
106 ms |
76108 KB |
n=50000 |
12 |
Correct |
105 ms |
76072 KB |
n=50000 |
13 |
Correct |
33 ms |
70728 KB |
n=10 |
14 |
Correct |
34 ms |
70764 KB |
n=685 |
15 |
Correct |
34 ms |
70868 KB |
n=623 |
16 |
Correct |
33 ms |
70760 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
70732 KB |
n=4 |
2 |
Correct |
33 ms |
70712 KB |
n=3 |
3 |
Correct |
34 ms |
70700 KB |
n=3 |
4 |
Correct |
34 ms |
70708 KB |
n=4 |
5 |
Correct |
33 ms |
70676 KB |
n=4 |
6 |
Correct |
32 ms |
70760 KB |
n=2 |
7 |
Correct |
36 ms |
70728 KB |
n=5 |
8 |
Correct |
32 ms |
70728 KB |
n=8 |
9 |
Correct |
33 ms |
70772 KB |
n=14 |
10 |
Correct |
33 ms |
70716 KB |
n=11 |
11 |
Correct |
106 ms |
76108 KB |
n=50000 |
12 |
Correct |
105 ms |
76072 KB |
n=50000 |
13 |
Correct |
33 ms |
70728 KB |
n=10 |
14 |
Correct |
34 ms |
70764 KB |
n=685 |
15 |
Correct |
34 ms |
70868 KB |
n=623 |
16 |
Correct |
33 ms |
70760 KB |
n=973 |
17 |
Correct |
37 ms |
70988 KB |
n=989 |
18 |
Correct |
34 ms |
70904 KB |
n=563 |
19 |
Correct |
36 ms |
70932 KB |
n=592 |
20 |
Correct |
37 ms |
70984 KB |
n=938 |
21 |
Correct |
36 ms |
70832 KB |
n=747 |
22 |
Correct |
36 ms |
70904 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1306 ms |
163524 KB |
n=1000000 |
2 |
Correct |
625 ms |
125864 KB |
n=666666 |
3 |
Correct |
316 ms |
103108 KB |
n=400000 |
4 |
Correct |
688 ms |
126372 KB |
n=285714 |
5 |
Correct |
43 ms |
72676 KB |
n=20000 |
6 |
Correct |
504 ms |
122084 KB |
n=181818 |
7 |
Correct |
37 ms |
71796 KB |
n=10000 |
8 |
Correct |
62 ms |
77312 KB |
n=6666 |
9 |
Correct |
36 ms |
71180 KB |
n=4000 |
10 |
Correct |
182 ms |
103324 KB |
n=2857 |
11 |
Correct |
34 ms |
71012 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
70732 KB |
n=4 |
2 |
Correct |
33 ms |
70712 KB |
n=3 |
3 |
Correct |
34 ms |
70700 KB |
n=3 |
4 |
Correct |
34 ms |
70708 KB |
n=4 |
5 |
Correct |
33 ms |
70676 KB |
n=4 |
6 |
Correct |
32 ms |
70760 KB |
n=2 |
7 |
Correct |
36 ms |
70728 KB |
n=5 |
8 |
Correct |
32 ms |
70728 KB |
n=8 |
9 |
Correct |
33 ms |
70772 KB |
n=14 |
10 |
Correct |
33 ms |
70716 KB |
n=11 |
11 |
Correct |
106 ms |
76108 KB |
n=50000 |
12 |
Correct |
105 ms |
76072 KB |
n=50000 |
13 |
Correct |
33 ms |
70728 KB |
n=10 |
14 |
Correct |
34 ms |
70764 KB |
n=685 |
15 |
Correct |
34 ms |
70868 KB |
n=623 |
16 |
Correct |
33 ms |
70760 KB |
n=973 |
17 |
Correct |
37 ms |
70988 KB |
n=989 |
18 |
Correct |
34 ms |
70904 KB |
n=563 |
19 |
Correct |
36 ms |
70932 KB |
n=592 |
20 |
Correct |
37 ms |
70984 KB |
n=938 |
21 |
Correct |
36 ms |
70832 KB |
n=747 |
22 |
Correct |
36 ms |
70904 KB |
n=991 |
23 |
Correct |
1306 ms |
163524 KB |
n=1000000 |
24 |
Correct |
625 ms |
125864 KB |
n=666666 |
25 |
Correct |
316 ms |
103108 KB |
n=400000 |
26 |
Correct |
688 ms |
126372 KB |
n=285714 |
27 |
Correct |
43 ms |
72676 KB |
n=20000 |
28 |
Correct |
504 ms |
122084 KB |
n=181818 |
29 |
Correct |
37 ms |
71796 KB |
n=10000 |
30 |
Correct |
62 ms |
77312 KB |
n=6666 |
31 |
Correct |
36 ms |
71180 KB |
n=4000 |
32 |
Correct |
182 ms |
103324 KB |
n=2857 |
33 |
Correct |
34 ms |
71012 KB |
n=2000 |
34 |
Correct |
77 ms |
73640 KB |
n=23514 |
35 |
Correct |
81 ms |
73660 KB |
n=23514 |
36 |
Correct |
35 ms |
70756 KB |
n=940 |
37 |
Correct |
34 ms |
70768 KB |
n=2 |
38 |
Correct |
272 ms |
87384 KB |
n=100000 |
39 |
Correct |
249 ms |
87336 KB |
n=100000 |
40 |
Correct |
38 ms |
70740 KB |
n=10 |
41 |
Correct |
40 ms |
70748 KB |
n=100 |
42 |
Correct |
40 ms |
71456 KB |
n=1000 |
43 |
Correct |
1994 ms |
194432 KB |
n=1000000 |
44 |
Execution timed out |
2041 ms |
207476 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |