#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define int long long
#define PI pair<int,int>
#define f first
#define s second
#define pb push_back
#define szo(x) ((int)x.size())
const int INF = 1e18;
const int maxn = 3e5+10;
int n, k;
int nums[maxn];
int dp[maxn];
int cnt[maxn];
PI solve(int m){
for (int i = 0; i <= n; ++i) dp[i] = 0, cnt[i] = 0;
int best = 0;
int idbest = 0;
for (int i = 1; i <= n; ++i){
dp[i] = dp[i-1];
cnt[i] = cnt[i-1];
best += nums[i];
if (best-m >= dp[i]){
dp[i] = best-m;
cnt[i] = cnt[idbest] + 1;
}
if ((dp[i] > best) || ((dp[i] == best) && cnt[i] >= cnt[idbest])){
best = dp[i];
idbest = i;
}
}
return {dp[n], cnt[n]};
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> nums[i];
int x = 1e18;
for (int b = 1e18; b >= 1; b >>= 1){
while (x-b >= 0 && solve(x-b).s <= k) x -= b;
}
cout << solve(x).f + k * x << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
7260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
7260 KB |
Output is correct |
2 |
Correct |
56 ms |
7260 KB |
Output is correct |
3 |
Correct |
59 ms |
7260 KB |
Output is correct |
4 |
Incorrect |
29 ms |
7260 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
7384 KB |
Output is correct |
2 |
Correct |
102 ms |
7380 KB |
Output is correct |
3 |
Correct |
99 ms |
7256 KB |
Output is correct |
4 |
Correct |
102 ms |
7260 KB |
Output is correct |
5 |
Correct |
102 ms |
7448 KB |
Output is correct |
6 |
Correct |
114 ms |
7260 KB |
Output is correct |
7 |
Correct |
101 ms |
7260 KB |
Output is correct |
8 |
Correct |
105 ms |
7448 KB |
Output is correct |
9 |
Correct |
115 ms |
7256 KB |
Output is correct |
10 |
Correct |
105 ms |
7256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
0 ms |
4560 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
0 ms |
4560 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
0 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
0 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
0 ms |
4560 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
0 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
0 ms |
4444 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
0 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4440 KB |
Output is correct |
22 |
Correct |
0 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4440 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4588 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
7260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |