#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 && 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 = 1e8;
for (int b = 1e8; b >= 1; b >>= 1){
while (x-b >= 0 && solve(x-b).s <= k) x -= b;
}
cout << solve(x).f + k * x << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
10076 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
8536 KB |
Output is correct |
2 |
Correct |
26 ms |
8540 KB |
Output is correct |
3 |
Correct |
28 ms |
8560 KB |
Output is correct |
4 |
Incorrect |
19 ms |
8540 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
62 ms |
10332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
10076 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |