#include "bits/stdc++.h"
using namespace std;
#define endl '\n'
#define debug(x) cerr << #x << " == " << (x) << '\n';
#define all(x) begin(x), end(x)
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
template<typename T>
bool chmin(T& x, T y) { return y < x ? (x = y, true) : false; }
template<typename T>
bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, K;
cin >> N >> K;
vector<int> A(N);
for (auto& x : A) cin >> x;
auto f = [&](ll z) {
ll dpmax = 0, prefsum = 0, prefmax = 0;
int cnt_dpmax = 0, cnt_prefmax = 0;
for (auto x : A) {
prefsum += x;
ll dp = prefsum + prefmax - z;
if (chmax(dpmax, dp)) cnt_dpmax = 1 + cnt_prefmax;
if (chmax(prefmax, dpmax - prefsum)) cnt_prefmax = cnt_dpmax;
}
return pair(dpmax, cnt_dpmax);
};
const ll inf = 1e10;
ll L = 0, R = inf;
while (L < R) {
ll M = L + (R - L) / 2;
f(M).second <= K ? R = M : L = M + 1;
}
auto [a, b] = f(L);
ll ans = a + b * L;
cout << ans << endl;
exit(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
4128 KB |
Output is correct |
2 |
Correct |
54 ms |
4280 KB |
Output is correct |
3 |
Correct |
54 ms |
4292 KB |
Output is correct |
4 |
Correct |
54 ms |
4276 KB |
Output is correct |
5 |
Correct |
57 ms |
4264 KB |
Output is correct |
6 |
Correct |
52 ms |
4252 KB |
Output is correct |
7 |
Correct |
52 ms |
4248 KB |
Output is correct |
8 |
Correct |
54 ms |
4292 KB |
Output is correct |
9 |
Correct |
53 ms |
4164 KB |
Output is correct |
10 |
Correct |
54 ms |
4292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
2484 KB |
Output is correct |
2 |
Correct |
45 ms |
2504 KB |
Output is correct |
3 |
Correct |
48 ms |
2600 KB |
Output is correct |
4 |
Correct |
43 ms |
2480 KB |
Output is correct |
5 |
Correct |
53 ms |
4164 KB |
Output is correct |
6 |
Correct |
44 ms |
2560 KB |
Output is correct |
7 |
Correct |
44 ms |
2636 KB |
Output is correct |
8 |
Correct |
53 ms |
4292 KB |
Output is correct |
9 |
Correct |
53 ms |
4292 KB |
Output is correct |
10 |
Correct |
43 ms |
2500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
78 ms |
4520 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
312 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
312 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 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 |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
4128 KB |
Output is correct |
2 |
Correct |
54 ms |
4280 KB |
Output is correct |
3 |
Correct |
54 ms |
4292 KB |
Output is correct |
4 |
Correct |
54 ms |
4276 KB |
Output is correct |
5 |
Correct |
57 ms |
4264 KB |
Output is correct |
6 |
Correct |
52 ms |
4252 KB |
Output is correct |
7 |
Correct |
52 ms |
4248 KB |
Output is correct |
8 |
Correct |
54 ms |
4292 KB |
Output is correct |
9 |
Correct |
53 ms |
4164 KB |
Output is correct |
10 |
Correct |
54 ms |
4292 KB |
Output is correct |
11 |
Correct |
47 ms |
2484 KB |
Output is correct |
12 |
Correct |
45 ms |
2504 KB |
Output is correct |
13 |
Correct |
48 ms |
2600 KB |
Output is correct |
14 |
Correct |
43 ms |
2480 KB |
Output is correct |
15 |
Correct |
53 ms |
4164 KB |
Output is correct |
16 |
Correct |
44 ms |
2560 KB |
Output is correct |
17 |
Correct |
44 ms |
2636 KB |
Output is correct |
18 |
Correct |
53 ms |
4292 KB |
Output is correct |
19 |
Correct |
53 ms |
4292 KB |
Output is correct |
20 |
Correct |
43 ms |
2500 KB |
Output is correct |
21 |
Incorrect |
78 ms |
4520 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |