# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
674755 |
2022-12-26T07:08:52 Z |
QwertyPi |
Feast (NOI19_feast) |
C++14 |
|
844 ms |
23896 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 3e5 + 11;
long double a[MAXN], dp[MAXN], dp2[MAXN], c[MAXN], c2[MAXN];
int32_t main(){
int n, k; cin >> n >> k;
for(int i = 0; i < n; i++){
cin >> a[i];
}
auto test = [&n](long double C) {
fill(dp, dp + MAXN, -(1LL << 60));
fill(dp2, dp2 + MAXN, -(1LL << 60));
fill(c, c + MAXN, 0);
fill(c2, c2 + MAXN, 0);
dp[0] = -(1LL << 60), dp2[0] = 0;
for(int j = 0; j < n; j++){
if(dp2[j - 1] + a[j] - C >= dp[j] + a[j]){
dp[j + 1] = dp2[j - 1] + a[j] - C;
c[j + 1] = c2[j - 1] + 1;
}else{
dp[j + 1] = dp[j] + a[j];
c[j + 1] = c[j];
}
if(dp2[j] >= dp[j + 1]){
dp2[j + 1] = dp2[j];
c2[j + 1] = c2[j];
}else{
dp2[j + 1] = dp[j + 1];
c2[j + 1] = c[j + 1];
}
}
};
long double l = 0, r = 1 << 30;
for(int tr = 0; tr < 60; tr++){
int mid = (l + r) / 2;
test(mid);
if(c2[n] > k){
l = mid;
}else{
r = mid;
}
}
test(l); long double v1 = dp2[n] + l * c2[n], k1 = c2[n];
test(r); long double v2 = dp2[n] + r * c2[n], k2 = c2[n];
cout << (int) v1 + (v2 - v1) / (k2 - k1) * (k - k1) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
674 ms |
23760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
614 ms |
23792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
844 ms |
23896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
282 ms |
19028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
282 ms |
19028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
282 ms |
19028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
674 ms |
23760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |