#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 [100010];
vector <long long int> ans [300010];
int main(){
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;
}
int ind=0;
for (int i=0; i<n; i++) if (a[i]>gr/k) {cout << -1; return 0;};
sort (s.begin(), s.end()); 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:29: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]
29 | for (int i=0; i<s.size(); i++){
| ~^~~~~~~~~
nicegift.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int j=0; j<ans [i].size(); j++) cout << ans [i][j] << " ";
| ~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
n=4 |
2 |
Correct |
4 ms |
7252 KB |
n=3 |
3 |
Correct |
4 ms |
7252 KB |
n=3 |
4 |
Correct |
5 ms |
7252 KB |
n=4 |
5 |
Correct |
4 ms |
7252 KB |
n=4 |
6 |
Correct |
4 ms |
7252 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
n=4 |
2 |
Correct |
4 ms |
7252 KB |
n=3 |
3 |
Correct |
4 ms |
7252 KB |
n=3 |
4 |
Correct |
5 ms |
7252 KB |
n=4 |
5 |
Correct |
4 ms |
7252 KB |
n=4 |
6 |
Correct |
4 ms |
7252 KB |
n=2 |
7 |
Correct |
4 ms |
7252 KB |
n=5 |
8 |
Correct |
4 ms |
7252 KB |
n=8 |
9 |
Correct |
4 ms |
7252 KB |
n=14 |
10 |
Correct |
5 ms |
7252 KB |
n=11 |
11 |
Correct |
108 ms |
12688 KB |
n=50000 |
12 |
Correct |
104 ms |
12472 KB |
n=50000 |
13 |
Correct |
4 ms |
7252 KB |
n=10 |
14 |
Correct |
5 ms |
7380 KB |
n=685 |
15 |
Correct |
5 ms |
7380 KB |
n=623 |
16 |
Correct |
8 ms |
7396 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
n=4 |
2 |
Correct |
4 ms |
7252 KB |
n=3 |
3 |
Correct |
4 ms |
7252 KB |
n=3 |
4 |
Correct |
5 ms |
7252 KB |
n=4 |
5 |
Correct |
4 ms |
7252 KB |
n=4 |
6 |
Correct |
4 ms |
7252 KB |
n=2 |
7 |
Correct |
4 ms |
7252 KB |
n=5 |
8 |
Correct |
4 ms |
7252 KB |
n=8 |
9 |
Correct |
4 ms |
7252 KB |
n=14 |
10 |
Correct |
5 ms |
7252 KB |
n=11 |
11 |
Correct |
108 ms |
12688 KB |
n=50000 |
12 |
Correct |
104 ms |
12472 KB |
n=50000 |
13 |
Correct |
4 ms |
7252 KB |
n=10 |
14 |
Correct |
5 ms |
7380 KB |
n=685 |
15 |
Correct |
5 ms |
7380 KB |
n=623 |
16 |
Correct |
8 ms |
7396 KB |
n=973 |
17 |
Correct |
8 ms |
7380 KB |
n=989 |
18 |
Correct |
6 ms |
7380 KB |
n=563 |
19 |
Correct |
8 ms |
7568 KB |
n=592 |
20 |
Correct |
7 ms |
7508 KB |
n=938 |
21 |
Correct |
9 ms |
7508 KB |
n=747 |
22 |
Correct |
6 ms |
7508 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
65 ms |
16152 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
n=4 |
2 |
Correct |
4 ms |
7252 KB |
n=3 |
3 |
Correct |
4 ms |
7252 KB |
n=3 |
4 |
Correct |
5 ms |
7252 KB |
n=4 |
5 |
Correct |
4 ms |
7252 KB |
n=4 |
6 |
Correct |
4 ms |
7252 KB |
n=2 |
7 |
Correct |
4 ms |
7252 KB |
n=5 |
8 |
Correct |
4 ms |
7252 KB |
n=8 |
9 |
Correct |
4 ms |
7252 KB |
n=14 |
10 |
Correct |
5 ms |
7252 KB |
n=11 |
11 |
Correct |
108 ms |
12688 KB |
n=50000 |
12 |
Correct |
104 ms |
12472 KB |
n=50000 |
13 |
Correct |
4 ms |
7252 KB |
n=10 |
14 |
Correct |
5 ms |
7380 KB |
n=685 |
15 |
Correct |
5 ms |
7380 KB |
n=623 |
16 |
Correct |
8 ms |
7396 KB |
n=973 |
17 |
Correct |
8 ms |
7380 KB |
n=989 |
18 |
Correct |
6 ms |
7380 KB |
n=563 |
19 |
Correct |
8 ms |
7568 KB |
n=592 |
20 |
Correct |
7 ms |
7508 KB |
n=938 |
21 |
Correct |
9 ms |
7508 KB |
n=747 |
22 |
Correct |
6 ms |
7508 KB |
n=991 |
23 |
Runtime error |
65 ms |
16152 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |