#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 10;
const long double EPS = 1e-3;
int N, K;
int a[MAX];
pair<long double, int> dp[MAX][2];
bool OK(long double lambda){
dp[0][0] = make_pair(0.0, 0);
dp[0][1] = make_pair(-1.18, 0);
for(int i=1; i<=N; i++){
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
dp[i][1] = max(make_pair(dp[i - 1][1].first + a[i], dp[i - 1][1].second),
make_pair(dp[i - 1][0].first + a[i] - lambda, dp[i - 1][0].second + 1));
}
return max(dp[N][0].second, dp[N][1].second) >= K;
}
int main(){
ios_base::sync_with_stdio(0);
cin >> N >> K;
for(int i=1; i<=N; i++){
cin >> a[i];
}
long double lo = 0, hi = 1e14;
while(lo + EPS < hi){
long double mid = (lo + hi) / 2;
if(OK(mid)){
lo = mid;
}
else{
hi = mid;
}
}
OK(lo);
cout << round(lo * K + max(dp[N][0], dp[N][1]).first);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
180 ms |
22876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
177 ms |
21324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
183 ms |
23124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
180 ms |
22876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |