#include <bits/stdc++.h>
#define pb emplace_back
#define pii pair<int,int>
#define ff first
#define ss second
#define All(x) x.begin(), x.end()
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 1000000;
int N, K;
int v[MAXN+1];
int sum, mmax;
vector <pii> arr;
set <int> num;
vector <int> ans;
void update(int x) {
if (x > 0)
num.erase(x);
else
num.insert(-x);
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> K;
for (int i = 1; i <= N; i++) {
cin >> v[i];
sum += v[i];
mmax = max(mmax, v[i]);
}
if (sum % K || mmax > sum / K) {
cout << -1 << '\n';
} else {
int now = 0;
for (int i = 1; i <= N; i++) {
arr.pb(now, -i);
now += v[i];
if (now > sum / K) {
arr.pb(sum / K, i);
now -= sum / K;
arr.pb(0, -i);
}
arr.pb(now, i);
}
sort(All(arr));
int pre;
for (int i = 0; i < arr.size(); i++) {
if (i) {
ans.pb(arr[i].ff - pre);
for (int j : num) ans.pb(j);
}
pre = arr[i].ff;
update(arr[i].ss);
while (i+1 < arr.size() && arr[i+1].ff == arr[i].ff) {
update(arr[++i].ss);
}
}
cout << ans.size() / (K+1) << '\n';
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << " \n"[i%(K+1)==K];
}
}
Compilation message
nicegift.cpp: In function 'int main()':
nicegift.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i = 0; i < arr.size(); i++) {
| ~~^~~~~~~~~~~~
nicegift.cpp:59:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | while (i+1 < arr.size() && arr[i+1].ff == arr[i].ff) {
| ~~~~^~~~~~~~~~~~
nicegift.cpp:64:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for (int i = 0; i < ans.size(); i++)
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
0 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
0 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
27 ms |
2920 KB |
n=50000 |
12 |
Correct |
26 ms |
2920 KB |
n=50000 |
13 |
Correct |
0 ms |
364 KB |
n=10 |
14 |
Correct |
1 ms |
364 KB |
n=685 |
15 |
Correct |
1 ms |
364 KB |
n=623 |
16 |
Correct |
1 ms |
364 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
0 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
27 ms |
2920 KB |
n=50000 |
12 |
Correct |
26 ms |
2920 KB |
n=50000 |
13 |
Correct |
0 ms |
364 KB |
n=10 |
14 |
Correct |
1 ms |
364 KB |
n=685 |
15 |
Correct |
1 ms |
364 KB |
n=623 |
16 |
Correct |
1 ms |
364 KB |
n=973 |
17 |
Correct |
1 ms |
384 KB |
n=989 |
18 |
Correct |
1 ms |
492 KB |
n=563 |
19 |
Correct |
2 ms |
492 KB |
n=592 |
20 |
Correct |
2 ms |
492 KB |
n=938 |
21 |
Correct |
2 ms |
492 KB |
n=747 |
22 |
Correct |
2 ms |
492 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
364 KB |
Jury has the answer but participant has not |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
0 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
27 ms |
2920 KB |
n=50000 |
12 |
Correct |
26 ms |
2920 KB |
n=50000 |
13 |
Correct |
0 ms |
364 KB |
n=10 |
14 |
Correct |
1 ms |
364 KB |
n=685 |
15 |
Correct |
1 ms |
364 KB |
n=623 |
16 |
Correct |
1 ms |
364 KB |
n=973 |
17 |
Correct |
1 ms |
384 KB |
n=989 |
18 |
Correct |
1 ms |
492 KB |
n=563 |
19 |
Correct |
2 ms |
492 KB |
n=592 |
20 |
Correct |
2 ms |
492 KB |
n=938 |
21 |
Correct |
2 ms |
492 KB |
n=747 |
22 |
Correct |
2 ms |
492 KB |
n=991 |
23 |
Incorrect |
11 ms |
364 KB |
Jury has the answer but participant has not |
24 |
Halted |
0 ms |
0 KB |
- |