//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#define ll long long
#define maxn 1000005
#define pii pair<int, ll>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
ll a[maxn], pref[maxn], val[maxn];
int out[3 * maxn];
bool ed[3 * maxn];
int main() {
io
ll n, k;
cin >> n >> k;
ll m = 0;
for (int i = 0;i < n;i++) {
cin >> a[i];
m += a[i];
pref[i] = m;
}
bool poss = m % k == 0;
ll siz = m / k;
int vs = 0;
for (int i = 0;i < n;i++) {
if (a[i] > siz) {
poss = false;
break;
}
val[vs++] = pref[i] % siz;
}
val[vs++] = siz;
sort(val, val + vs);
if (!poss) {
cout << -1 << endl;
} else {
int num = 0, cnt = 0;
ll cur = 0;
for (int i = 0;i < vs;i++) {
//cout << val[i] << " " << cur << endl;
if (val[i] - cur > 0) { //[cur, val[i])
out[num++] = val[i] - cur;
int ind = upper_bound(pref, pref + n, cur) - pref;
for (ll j = cur;j < m;j += m / k) {
ind = upper_bound(pref, pref + n, j) - pref;
if (ind < n) out[num++] = ind+1;
}
ed[num - 1] = true;
cur = val[i];
cnt++;
}
}
cout << cnt << "\n";
for (int i = 0;i < num;i++) {
cout << out[i] << (ed[i] ? '\n' : ' ');
}
}
}
/*
4 2
2 3 3 2
6 4
4 1 3 5 5 2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 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 |
24 ms |
2796 KB |
n=50000 |
12 |
Correct |
24 ms |
2668 KB |
n=50000 |
13 |
Correct |
1 ms |
376 KB |
n=10 |
14 |
Correct |
1 ms |
384 KB |
n=685 |
15 |
Correct |
2 ms |
364 KB |
n=623 |
16 |
Correct |
1 ms |
492 KB |
n=973 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 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 |
24 ms |
2796 KB |
n=50000 |
12 |
Correct |
24 ms |
2668 KB |
n=50000 |
13 |
Correct |
1 ms |
376 KB |
n=10 |
14 |
Correct |
1 ms |
384 KB |
n=685 |
15 |
Correct |
2 ms |
364 KB |
n=623 |
16 |
Correct |
1 ms |
492 KB |
n=973 |
17 |
Correct |
1 ms |
492 KB |
n=989 |
18 |
Correct |
2 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 |
3 ms |
492 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
514 ms |
43756 KB |
Added number should be positive |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 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 |
24 ms |
2796 KB |
n=50000 |
12 |
Correct |
24 ms |
2668 KB |
n=50000 |
13 |
Correct |
1 ms |
376 KB |
n=10 |
14 |
Correct |
1 ms |
384 KB |
n=685 |
15 |
Correct |
2 ms |
364 KB |
n=623 |
16 |
Correct |
1 ms |
492 KB |
n=973 |
17 |
Correct |
1 ms |
492 KB |
n=989 |
18 |
Correct |
2 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 |
3 ms |
492 KB |
n=991 |
23 |
Incorrect |
514 ms |
43756 KB |
Added number should be positive |
24 |
Halted |
0 ms |
0 KB |
- |