#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 1e6 + 7;
ll a[N];
signed main()
{
IO_OP;
int n, k;
cin >> n >> k;
ll sum = 0, mx = 0;
for(int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
mx = max(mx, a[i]);
}
if(sum % k || mx > sum / k) {
cout << -1 << '\n';
return 0;
}
V<array<ll, 3>> ev;
auto add_event = [&] (ll l, ll r, int i) { // [l, r)
assert(l < r);
ev.PB({l, 1, i});
ev.PB({r, -1, i});
};
ll psum = 0;
for(int i = 0; i < n; i++) {
if(a[i] >= sum / k) add_event(0, sum / k, i + 1);
else {
ll lb = psum % (sum / k), rb = (lb + a[i] - 1) % (sum / k);
if(lb <= rb) add_event(lb, rb + 1, i + 1);
else add_event(0, rb + 1, i + 1), add_event(lb, sum / k, i + 1);
}
psum += a[i];
}
sort(ALL(ev));
set<int> who;
int lst = -1;
V<ll> ans;
for(auto e:ev) {
if(lst != -1 && e[0] != lst) {
// assert(int(who.size()) == k);
ll x = e[0] - lst;
ans.PB(x);
for(int i:who)
ans.PB(i);
}
if(e[1] == 1) { // add
assert(who.count(e[2]) == 0);
who.insert(e[2]);
} else {
assert(who.count(e[2]) == 1);
who.erase(e[2]);
}
// assert(int(who.size()) <= k);
lst = e[0];
}
cout << int(ans.size()) / (k + 1) << '\n';
for(int i = 0; i < int(ans.size()); i++)
cout << ans[i] << " \n"[i % (k + 1) == k];
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
364 KB |
n=5 |
8 |
Correct |
0 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
42 ms |
5724 KB |
n=50000 |
12 |
Correct |
39 ms |
5596 KB |
n=50000 |
13 |
Correct |
1 ms |
364 KB |
n=10 |
14 |
Correct |
1 ms |
492 KB |
n=685 |
15 |
Correct |
1 ms |
492 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 |
0 ms |
364 KB |
n=5 |
8 |
Correct |
0 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
42 ms |
5724 KB |
n=50000 |
12 |
Correct |
39 ms |
5596 KB |
n=50000 |
13 |
Correct |
1 ms |
364 KB |
n=10 |
14 |
Correct |
1 ms |
492 KB |
n=685 |
15 |
Correct |
1 ms |
492 KB |
n=623 |
16 |
Correct |
1 ms |
492 KB |
n=973 |
17 |
Correct |
1 ms |
492 KB |
n=989 |
18 |
Correct |
1 ms |
492 KB |
n=563 |
19 |
Correct |
2 ms |
620 KB |
n=592 |
20 |
Correct |
3 ms |
748 KB |
n=938 |
21 |
Correct |
2 ms |
560 KB |
n=747 |
22 |
Correct |
3 ms |
748 KB |
n=991 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1290 ms |
171148 KB |
Taken too much stones from the heap |
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 |
0 ms |
364 KB |
n=5 |
8 |
Correct |
0 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
42 ms |
5724 KB |
n=50000 |
12 |
Correct |
39 ms |
5596 KB |
n=50000 |
13 |
Correct |
1 ms |
364 KB |
n=10 |
14 |
Correct |
1 ms |
492 KB |
n=685 |
15 |
Correct |
1 ms |
492 KB |
n=623 |
16 |
Correct |
1 ms |
492 KB |
n=973 |
17 |
Correct |
1 ms |
492 KB |
n=989 |
18 |
Correct |
1 ms |
492 KB |
n=563 |
19 |
Correct |
2 ms |
620 KB |
n=592 |
20 |
Correct |
3 ms |
748 KB |
n=938 |
21 |
Correct |
2 ms |
560 KB |
n=747 |
22 |
Correct |
3 ms |
748 KB |
n=991 |
23 |
Incorrect |
1290 ms |
171148 KB |
Taken too much stones from the heap |
24 |
Halted |
0 ms |
0 KB |
- |