-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathleaves.cpp
42 lines (34 loc) · 891 Bytes
/
leaves.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
# include <cstdio>
# include <algorithm>
# include <deque>
# define NR 100005
using namespace std;
int i,j,n,m,x,y,K;
long long S[NR], SS[NR], a[NR][14], nr[NR];
long long suma (int I, int J, int ant) {
long long S=0;
S=a[J][ant] + (SS[I] -
}
int main ()
{
freopen ("leaves.in", "r", stdin);
freopen ("leaves.out", "w", stdout);
scanf ("%d%d", &n, &K);
// S[i]- suma elementelor 1 - i
// SS[i]- suma triunghiulara a elementelor
for (i=1; i<=n; ++i) scanf ("%d", &nr[i]);
for (i=n; i>=1; --i) {
S[i]=S[i+1] + nr[i];
SS[i]=SS[i+1] + S[i];
a[i][1]=SS[i];
}
cs=n;
for (j=2; j<=K; ++j) pentru fiecare gramada
for (i=n; i>=1; --i) {//fiecare pozitie
// actualizam cs
while (i<=cs) {
if (suma(i, cs-1, j-1) <= suma(i, cs)) --cs;
}
}
return 0;
}