#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define mp make_pair
#define stMx(a,b) a = max(a,b)
typedef pair<int,int> ii;
#define REP(i, a, b) for(int i = a; i < b; i++)
int32_t main() {
int N, K; cin >> N >> K; int A[N+1]; A[0]=0;
REP(i,1,N+1) {
cin>>A[i];
A[i]+=A[i-1];
}
ii dp[N+1];
int l = -1, h = 300000000000005;
while(h-l>1){
dp[0]=mp(0,0);
int lambda = (l+h)/2;
ii best = mp(0,0);
REP(i,1,N+1) {
dp[i]=max(dp[i-1],mp(A[i]+best.fi-lambda,best.se-1));
stMx(best,mp(dp[i].fi-A[i],dp[i].se));
}
if(dp[N].se>=-1*K) h=lambda;
else l=lambda;
}
ii best = mp(0,0);
REP(i,1,N+1) {
dp[i]=max(dp[i-1],mp(A[i]+best.fi-h,best.se-1));
stMx(best,mp(dp[i].fi-A[i],dp[i].se));
}
cout << dp[N].fi+h*K;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
7156 KB |
Output is correct |
2 |
Correct |
142 ms |
7200 KB |
Output is correct |
3 |
Correct |
182 ms |
7284 KB |
Output is correct |
4 |
Correct |
135 ms |
7256 KB |
Output is correct |
5 |
Correct |
138 ms |
7216 KB |
Output is correct |
6 |
Correct |
141 ms |
7164 KB |
Output is correct |
7 |
Correct |
141 ms |
7160 KB |
Output is correct |
8 |
Correct |
135 ms |
7328 KB |
Output is correct |
9 |
Correct |
130 ms |
7248 KB |
Output is correct |
10 |
Correct |
142 ms |
7372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
7052 KB |
Output is correct |
2 |
Correct |
92 ms |
7396 KB |
Output is correct |
3 |
Correct |
92 ms |
7180 KB |
Output is correct |
4 |
Correct |
90 ms |
7320 KB |
Output is correct |
5 |
Correct |
129 ms |
7164 KB |
Output is correct |
6 |
Correct |
88 ms |
7156 KB |
Output is correct |
7 |
Correct |
95 ms |
7356 KB |
Output is correct |
8 |
Correct |
140 ms |
7340 KB |
Output is correct |
9 |
Correct |
132 ms |
7116 KB |
Output is correct |
10 |
Correct |
90 ms |
7396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
7204 KB |
Output is correct |
2 |
Correct |
167 ms |
7180 KB |
Output is correct |
3 |
Correct |
166 ms |
7464 KB |
Output is correct |
4 |
Correct |
175 ms |
7244 KB |
Output is correct |
5 |
Correct |
160 ms |
7320 KB |
Output is correct |
6 |
Correct |
177 ms |
7340 KB |
Output is correct |
7 |
Correct |
182 ms |
7408 KB |
Output is correct |
8 |
Correct |
167 ms |
7448 KB |
Output is correct |
9 |
Correct |
175 ms |
7424 KB |
Output is correct |
10 |
Correct |
172 ms |
7408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
7156 KB |
Output is correct |
2 |
Correct |
142 ms |
7200 KB |
Output is correct |
3 |
Correct |
182 ms |
7284 KB |
Output is correct |
4 |
Correct |
135 ms |
7256 KB |
Output is correct |
5 |
Correct |
138 ms |
7216 KB |
Output is correct |
6 |
Correct |
141 ms |
7164 KB |
Output is correct |
7 |
Correct |
141 ms |
7160 KB |
Output is correct |
8 |
Correct |
135 ms |
7328 KB |
Output is correct |
9 |
Correct |
130 ms |
7248 KB |
Output is correct |
10 |
Correct |
142 ms |
7372 KB |
Output is correct |
11 |
Correct |
89 ms |
7052 KB |
Output is correct |
12 |
Correct |
92 ms |
7396 KB |
Output is correct |
13 |
Correct |
92 ms |
7180 KB |
Output is correct |
14 |
Correct |
90 ms |
7320 KB |
Output is correct |
15 |
Correct |
129 ms |
7164 KB |
Output is correct |
16 |
Correct |
88 ms |
7156 KB |
Output is correct |
17 |
Correct |
95 ms |
7356 KB |
Output is correct |
18 |
Correct |
140 ms |
7340 KB |
Output is correct |
19 |
Correct |
132 ms |
7116 KB |
Output is correct |
20 |
Correct |
90 ms |
7396 KB |
Output is correct |
21 |
Correct |
175 ms |
7204 KB |
Output is correct |
22 |
Correct |
167 ms |
7180 KB |
Output is correct |
23 |
Correct |
166 ms |
7464 KB |
Output is correct |
24 |
Correct |
175 ms |
7244 KB |
Output is correct |
25 |
Correct |
160 ms |
7320 KB |
Output is correct |
26 |
Correct |
177 ms |
7340 KB |
Output is correct |
27 |
Correct |
182 ms |
7408 KB |
Output is correct |
28 |
Correct |
167 ms |
7448 KB |
Output is correct |
29 |
Correct |
175 ms |
7424 KB |
Output is correct |
30 |
Correct |
172 ms |
7408 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
300 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
300 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
3 ms |
340 KB |
Output is correct |
52 |
Correct |
2 ms |
332 KB |
Output is correct |
53 |
Correct |
2 ms |
340 KB |
Output is correct |
54 |
Correct |
2 ms |
340 KB |
Output is correct |
55 |
Correct |
2 ms |
340 KB |
Output is correct |
56 |
Correct |
2 ms |
340 KB |
Output is correct |
57 |
Correct |
2 ms |
340 KB |
Output is correct |
58 |
Correct |
2 ms |
340 KB |
Output is correct |
59 |
Correct |
2 ms |
340 KB |
Output is correct |
60 |
Correct |
2 ms |
340 KB |
Output is correct |
61 |
Correct |
209 ms |
7168 KB |
Output is correct |
62 |
Correct |
198 ms |
7352 KB |
Output is correct |
63 |
Correct |
175 ms |
7292 KB |
Output is correct |
64 |
Correct |
205 ms |
7384 KB |
Output is correct |
65 |
Correct |
208 ms |
7376 KB |
Output is correct |
66 |
Correct |
200 ms |
7360 KB |
Output is correct |
67 |
Correct |
220 ms |
7252 KB |
Output is correct |
68 |
Correct |
172 ms |
7336 KB |
Output is correct |
69 |
Correct |
181 ms |
7176 KB |
Output is correct |
70 |
Correct |
161 ms |
7156 KB |
Output is correct |