#include <bits/stdc++.h>
using namespace std;
vector < pair <long long int, pair<int, int> > > s;
set <int> m;
long long int a [100010];
vector <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++){
int x=s [i].first; int y=s[i].second.first; 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<int, 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<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 |
3 ms |
7252 KB |
n=3 |
3 |
Correct |
3 ms |
7252 KB |
n=3 |
4 |
Correct |
3 ms |
7252 KB |
n=4 |
5 |
Correct |
3 ms |
7252 KB |
n=4 |
6 |
Correct |
3 ms |
7252 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
n=4 |
2 |
Correct |
3 ms |
7252 KB |
n=3 |
3 |
Correct |
3 ms |
7252 KB |
n=3 |
4 |
Correct |
3 ms |
7252 KB |
n=4 |
5 |
Correct |
3 ms |
7252 KB |
n=4 |
6 |
Correct |
3 ms |
7252 KB |
n=2 |
7 |
Correct |
3 ms |
7252 KB |
n=5 |
8 |
Correct |
4 ms |
7252 KB |
n=8 |
9 |
Correct |
3 ms |
7252 KB |
n=14 |
10 |
Correct |
3 ms |
7252 KB |
n=11 |
11 |
Correct |
85 ms |
11156 KB |
n=50000 |
12 |
Correct |
80 ms |
11132 KB |
n=50000 |
13 |
Correct |
3 ms |
7252 KB |
n=10 |
14 |
Correct |
5 ms |
7380 KB |
n=685 |
15 |
Correct |
6 ms |
7380 KB |
n=623 |
16 |
Correct |
6 ms |
7380 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
n=4 |
2 |
Correct |
3 ms |
7252 KB |
n=3 |
3 |
Correct |
3 ms |
7252 KB |
n=3 |
4 |
Correct |
3 ms |
7252 KB |
n=4 |
5 |
Correct |
3 ms |
7252 KB |
n=4 |
6 |
Correct |
3 ms |
7252 KB |
n=2 |
7 |
Correct |
3 ms |
7252 KB |
n=5 |
8 |
Correct |
4 ms |
7252 KB |
n=8 |
9 |
Correct |
3 ms |
7252 KB |
n=14 |
10 |
Correct |
3 ms |
7252 KB |
n=11 |
11 |
Correct |
85 ms |
11156 KB |
n=50000 |
12 |
Correct |
80 ms |
11132 KB |
n=50000 |
13 |
Correct |
3 ms |
7252 KB |
n=10 |
14 |
Correct |
5 ms |
7380 KB |
n=685 |
15 |
Correct |
6 ms |
7380 KB |
n=623 |
16 |
Correct |
6 ms |
7380 KB |
n=973 |
17 |
Correct |
6 ms |
7380 KB |
n=989 |
18 |
Correct |
6 ms |
7380 KB |
n=563 |
19 |
Correct |
6 ms |
7484 KB |
n=592 |
20 |
Correct |
6 ms |
7508 KB |
n=938 |
21 |
Correct |
6 ms |
7464 KB |
n=747 |
22 |
Correct |
7 ms |
7424 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
55 ms |
16208 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 |
3 ms |
7252 KB |
n=3 |
3 |
Correct |
3 ms |
7252 KB |
n=3 |
4 |
Correct |
3 ms |
7252 KB |
n=4 |
5 |
Correct |
3 ms |
7252 KB |
n=4 |
6 |
Correct |
3 ms |
7252 KB |
n=2 |
7 |
Correct |
3 ms |
7252 KB |
n=5 |
8 |
Correct |
4 ms |
7252 KB |
n=8 |
9 |
Correct |
3 ms |
7252 KB |
n=14 |
10 |
Correct |
3 ms |
7252 KB |
n=11 |
11 |
Correct |
85 ms |
11156 KB |
n=50000 |
12 |
Correct |
80 ms |
11132 KB |
n=50000 |
13 |
Correct |
3 ms |
7252 KB |
n=10 |
14 |
Correct |
5 ms |
7380 KB |
n=685 |
15 |
Correct |
6 ms |
7380 KB |
n=623 |
16 |
Correct |
6 ms |
7380 KB |
n=973 |
17 |
Correct |
6 ms |
7380 KB |
n=989 |
18 |
Correct |
6 ms |
7380 KB |
n=563 |
19 |
Correct |
6 ms |
7484 KB |
n=592 |
20 |
Correct |
6 ms |
7508 KB |
n=938 |
21 |
Correct |
6 ms |
7464 KB |
n=747 |
22 |
Correct |
7 ms |
7424 KB |
n=991 |
23 |
Runtime error |
55 ms |
16208 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |