#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vi = vector<int>;
using vvi = vector<vi>;
using pll = pair<ll, ll>;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, K;
cin >> N >> K;
vll A(1+N);
for(int i = 1; i <= N; i++) cin >> A[i];
ll lo = 0, hi = 1'000'000'000'000'000'000LL;
while(1)
{
ll cost = (lo+hi)/2;
vector<pll> dp0(1+N);
vector<pll> dp1(1+N);
dp0[0] = {0LL, 0LL};
dp1[0] = {-cost, -1LL};
for(int i = 1; i <= N; i++)
{
dp0[i] = max(dp0[i-1], dp1[i-1]);
dp1[i] = max(pll{dp1[i-1].first + A[i], dp1[i-1].second}, pll{dp0[i-1].first + A[i] - cost, dp0[i-1].second - 1});
}
pair<ll, int> X = max(dp0[N], dp1[N]);
bool works = (-X.second <= K);
if(lo == hi)
{
cout << X.first - cost*X.second << '\n';
return 0;
}
else
{
if(works)
hi = cost;
else
lo = cost+1;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
298 ms |
14568 KB |
Output is correct |
2 |
Correct |
306 ms |
14860 KB |
Output is correct |
3 |
Correct |
328 ms |
15088 KB |
Output is correct |
4 |
Correct |
310 ms |
15088 KB |
Output is correct |
5 |
Correct |
316 ms |
14980 KB |
Output is correct |
6 |
Correct |
301 ms |
14560 KB |
Output is correct |
7 |
Correct |
294 ms |
14712 KB |
Output is correct |
8 |
Correct |
380 ms |
14880 KB |
Output is correct |
9 |
Correct |
300 ms |
14696 KB |
Output is correct |
10 |
Correct |
307 ms |
14872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
312 ms |
13224 KB |
Output is correct |
2 |
Correct |
296 ms |
13404 KB |
Output is correct |
3 |
Correct |
312 ms |
13012 KB |
Output is correct |
4 |
Correct |
295 ms |
13116 KB |
Output is correct |
5 |
Correct |
352 ms |
14640 KB |
Output is correct |
6 |
Correct |
285 ms |
13328 KB |
Output is correct |
7 |
Correct |
340 ms |
13368 KB |
Output is correct |
8 |
Correct |
306 ms |
15000 KB |
Output is correct |
9 |
Correct |
315 ms |
14604 KB |
Output is correct |
10 |
Correct |
296 ms |
13320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
310 ms |
15196 KB |
Output is correct |
2 |
Correct |
294 ms |
14880 KB |
Output is correct |
3 |
Correct |
304 ms |
15132 KB |
Output is correct |
4 |
Correct |
296 ms |
14912 KB |
Output is correct |
5 |
Correct |
310 ms |
15028 KB |
Output is correct |
6 |
Correct |
307 ms |
15080 KB |
Output is correct |
7 |
Correct |
295 ms |
15096 KB |
Output is correct |
8 |
Correct |
317 ms |
14988 KB |
Output is correct |
9 |
Correct |
307 ms |
15232 KB |
Output is correct |
10 |
Correct |
311 ms |
15232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
324 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
298 ms |
14568 KB |
Output is correct |
2 |
Correct |
306 ms |
14860 KB |
Output is correct |
3 |
Correct |
328 ms |
15088 KB |
Output is correct |
4 |
Correct |
310 ms |
15088 KB |
Output is correct |
5 |
Correct |
316 ms |
14980 KB |
Output is correct |
6 |
Correct |
301 ms |
14560 KB |
Output is correct |
7 |
Correct |
294 ms |
14712 KB |
Output is correct |
8 |
Correct |
380 ms |
14880 KB |
Output is correct |
9 |
Correct |
300 ms |
14696 KB |
Output is correct |
10 |
Correct |
307 ms |
14872 KB |
Output is correct |
11 |
Correct |
312 ms |
13224 KB |
Output is correct |
12 |
Correct |
296 ms |
13404 KB |
Output is correct |
13 |
Correct |
312 ms |
13012 KB |
Output is correct |
14 |
Correct |
295 ms |
13116 KB |
Output is correct |
15 |
Correct |
352 ms |
14640 KB |
Output is correct |
16 |
Correct |
285 ms |
13328 KB |
Output is correct |
17 |
Correct |
340 ms |
13368 KB |
Output is correct |
18 |
Correct |
306 ms |
15000 KB |
Output is correct |
19 |
Correct |
315 ms |
14604 KB |
Output is correct |
20 |
Correct |
296 ms |
13320 KB |
Output is correct |
21 |
Correct |
310 ms |
15196 KB |
Output is correct |
22 |
Correct |
294 ms |
14880 KB |
Output is correct |
23 |
Correct |
304 ms |
15132 KB |
Output is correct |
24 |
Correct |
296 ms |
14912 KB |
Output is correct |
25 |
Correct |
310 ms |
15028 KB |
Output is correct |
26 |
Correct |
307 ms |
15080 KB |
Output is correct |
27 |
Correct |
295 ms |
15096 KB |
Output is correct |
28 |
Correct |
317 ms |
14988 KB |
Output is correct |
29 |
Correct |
307 ms |
15232 KB |
Output is correct |
30 |
Correct |
311 ms |
15232 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
0 ms |
204 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
312 KB |
Output is correct |
41 |
Correct |
1 ms |
308 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
0 ms |
204 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
316 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
0 ms |
204 KB |
Output is correct |
50 |
Correct |
0 ms |
332 KB |
Output is correct |
51 |
Correct |
1 ms |
332 KB |
Output is correct |
52 |
Correct |
1 ms |
332 KB |
Output is correct |
53 |
Correct |
1 ms |
332 KB |
Output is correct |
54 |
Correct |
1 ms |
332 KB |
Output is correct |
55 |
Correct |
1 ms |
332 KB |
Output is correct |
56 |
Correct |
2 ms |
324 KB |
Output is correct |
57 |
Correct |
1 ms |
460 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
1 ms |
332 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
337 ms |
14996 KB |
Output is correct |
62 |
Correct |
342 ms |
15376 KB |
Output is correct |
63 |
Correct |
306 ms |
14792 KB |
Output is correct |
64 |
Correct |
336 ms |
15152 KB |
Output is correct |
65 |
Correct |
341 ms |
15076 KB |
Output is correct |
66 |
Correct |
368 ms |
15136 KB |
Output is correct |
67 |
Correct |
338 ms |
14920 KB |
Output is correct |
68 |
Correct |
339 ms |
15124 KB |
Output is correct |
69 |
Correct |
283 ms |
14888 KB |
Output is correct |
70 |
Correct |
308 ms |
14732 KB |
Output is correct |