#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using ull = unsigned long long;
#define X first
#define Y second
#define SZ(x) int(x.size())
#define all(x) x.begin(), x.end()
#define mins(a,b) (a = min(a,b))
#define maxs(a,b) (a = max(a,b))
#define pb push_back
#define Mp make_pair
#define lc id<<1
#define rc lc|1
// #define mid ((l+r)/2)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll INF = 1e9 + 23;
const ll MOD = 1e9 + 7;
const int MXN = 3e5 + 5;
const int LOG = 23;
int n, k, a[MXN];
pll calc(ll lmb) {
pll mx = Mp(0, 0), ans = mx;
ll sum=0;
for(int i=1; i<=n; i++) {
sum += a[i];
maxs(ans, Mp(mx.X+sum-lmb, mx.Y+1));
maxs(mx, Mp(ans.X-sum, ans.Y));
}
return ans;
}
void Main() {
cin >> n >> k;
for(int i=1; i<=n; i++) cin >> a[i];
// ll l=-1, r=1e18;
// while(r-l>1)
// (calc(mid).Y>=k ? l : r) = mid;
// cout << calc(l).X + l*k << '\n';
ll lo = 0;
ll hi = 1e18;
while (lo < hi) {
ll mid = (lo + hi + 1) / 2;
calc(mid).second >= k ? lo = mid : hi = mid - 1;
}
cout << calc(lo).first + lo * k << endl;
}
int32_t main() {
cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
int T = 1;
// cin >> T;
while(T--) Main();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
1360 KB |
Output is correct |
2 |
Correct |
64 ms |
4368 KB |
Output is correct |
3 |
Correct |
49 ms |
4432 KB |
Output is correct |
4 |
Correct |
50 ms |
4600 KB |
Output is correct |
5 |
Correct |
50 ms |
4432 KB |
Output is correct |
6 |
Correct |
49 ms |
4260 KB |
Output is correct |
7 |
Correct |
47 ms |
4176 KB |
Output is correct |
8 |
Correct |
48 ms |
4432 KB |
Output is correct |
9 |
Correct |
64 ms |
4208 KB |
Output is correct |
10 |
Correct |
48 ms |
4152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
1608 KB |
Output is correct |
2 |
Correct |
43 ms |
1624 KB |
Output is correct |
3 |
Correct |
43 ms |
1360 KB |
Output is correct |
4 |
Correct |
39 ms |
1616 KB |
Output is correct |
5 |
Correct |
51 ms |
4020 KB |
Output is correct |
6 |
Correct |
43 ms |
2568 KB |
Output is correct |
7 |
Correct |
47 ms |
2640 KB |
Output is correct |
8 |
Correct |
53 ms |
4168 KB |
Output is correct |
9 |
Correct |
53 ms |
4176 KB |
Output is correct |
10 |
Correct |
42 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
1616 KB |
Output is correct |
2 |
Correct |
75 ms |
1360 KB |
Output is correct |
3 |
Correct |
97 ms |
1608 KB |
Output is correct |
4 |
Correct |
75 ms |
1360 KB |
Output is correct |
5 |
Correct |
69 ms |
1492 KB |
Output is correct |
6 |
Correct |
70 ms |
1616 KB |
Output is correct |
7 |
Correct |
71 ms |
1616 KB |
Output is correct |
8 |
Correct |
69 ms |
1616 KB |
Output is correct |
9 |
Correct |
83 ms |
1616 KB |
Output is correct |
10 |
Correct |
73 ms |
1616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
444 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
444 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
504 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
336 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
1360 KB |
Output is correct |
2 |
Correct |
64 ms |
4368 KB |
Output is correct |
3 |
Correct |
49 ms |
4432 KB |
Output is correct |
4 |
Correct |
50 ms |
4600 KB |
Output is correct |
5 |
Correct |
50 ms |
4432 KB |
Output is correct |
6 |
Correct |
49 ms |
4260 KB |
Output is correct |
7 |
Correct |
47 ms |
4176 KB |
Output is correct |
8 |
Correct |
48 ms |
4432 KB |
Output is correct |
9 |
Correct |
64 ms |
4208 KB |
Output is correct |
10 |
Correct |
48 ms |
4152 KB |
Output is correct |
11 |
Correct |
42 ms |
1608 KB |
Output is correct |
12 |
Correct |
43 ms |
1624 KB |
Output is correct |
13 |
Correct |
43 ms |
1360 KB |
Output is correct |
14 |
Correct |
39 ms |
1616 KB |
Output is correct |
15 |
Correct |
51 ms |
4020 KB |
Output is correct |
16 |
Correct |
43 ms |
2568 KB |
Output is correct |
17 |
Correct |
47 ms |
2640 KB |
Output is correct |
18 |
Correct |
53 ms |
4168 KB |
Output is correct |
19 |
Correct |
53 ms |
4176 KB |
Output is correct |
20 |
Correct |
42 ms |
2640 KB |
Output is correct |
21 |
Correct |
107 ms |
1616 KB |
Output is correct |
22 |
Correct |
75 ms |
1360 KB |
Output is correct |
23 |
Correct |
97 ms |
1608 KB |
Output is correct |
24 |
Correct |
75 ms |
1360 KB |
Output is correct |
25 |
Correct |
69 ms |
1492 KB |
Output is correct |
26 |
Correct |
70 ms |
1616 KB |
Output is correct |
27 |
Correct |
71 ms |
1616 KB |
Output is correct |
28 |
Correct |
69 ms |
1616 KB |
Output is correct |
29 |
Correct |
83 ms |
1616 KB |
Output is correct |
30 |
Correct |
73 ms |
1616 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
504 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
444 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
504 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
504 KB |
Output is correct |
51 |
Correct |
1 ms |
336 KB |
Output is correct |
52 |
Correct |
1 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
54 |
Correct |
1 ms |
336 KB |
Output is correct |
55 |
Correct |
1 ms |
336 KB |
Output is correct |
56 |
Correct |
2 ms |
336 KB |
Output is correct |
57 |
Correct |
2 ms |
336 KB |
Output is correct |
58 |
Correct |
2 ms |
336 KB |
Output is correct |
59 |
Correct |
1 ms |
336 KB |
Output is correct |
60 |
Correct |
1 ms |
336 KB |
Output is correct |
61 |
Correct |
121 ms |
4432 KB |
Output is correct |
62 |
Correct |
107 ms |
4684 KB |
Output is correct |
63 |
Correct |
89 ms |
4432 KB |
Output is correct |
64 |
Correct |
146 ms |
4400 KB |
Output is correct |
65 |
Correct |
116 ms |
4424 KB |
Output is correct |
66 |
Correct |
118 ms |
4676 KB |
Output is correct |
67 |
Correct |
136 ms |
4424 KB |
Output is correct |
68 |
Correct |
90 ms |
4448 KB |
Output is correct |
69 |
Correct |
75 ms |
4432 KB |
Output is correct |
70 |
Correct |
106 ms |
4432 KB |
Output is correct |