-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathD.cpp
47 lines (36 loc) · 818 Bytes
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll ara[100009], pos[100009], sum = 0;
int main()
{
ll n, l;
cin >> n >> l;
for(ll i = 1; i < n; i++)
scanf("%lld", &ara[i]);
pos[0] = 1e18;
for(ll i = 0; i < n; i++) {
ll cnt = pos[i];
for(ll j = i + l; j > i; j--) {
if(cnt <= 0)
break;
if(j >= n) {
sum += cnt;
cnt = 0;
break;
}
if(ara[j] >= cnt) {
ara[j] -= cnt;
pos[j] += cnt;
cnt = 0;
}
else {
pos[j] += ara[j];
cnt -= ara[j];
ara[j] = 0;
}
}
}
cout << sum << endl;
return 0;
}