# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
674761 |
2022-12-26T07:30:20 Z |
QwertyPi |
Feast (NOI19_feast) |
C++14 |
|
200 ms |
14948 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 3e5 + 11;
int 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](int 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];
}
}
};
int l = 0, r = 1 << 30;
while(l + 1 != r){
int mid = (l + r) / 2;
test(mid);
if(c2[n] > k){
l = mid;
}else{
r = mid;
}
}
test(l); int v1 = dp2[n] + l * c2[n], k1 = c2[n];
test(r); int v2 = dp2[n] + r * c2[n], k2 = c2[n];
cout << v1 + (k1 != k2 ? (v2 - v1) / (k2 - k1) * (k - k1) : 0) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
11848 KB |
Output is correct |
2 |
Correct |
162 ms |
14880 KB |
Output is correct |
3 |
Correct |
155 ms |
14948 KB |
Output is correct |
4 |
Correct |
153 ms |
14864 KB |
Output is correct |
5 |
Correct |
155 ms |
14820 KB |
Output is correct |
6 |
Correct |
162 ms |
14728 KB |
Output is correct |
7 |
Correct |
163 ms |
14652 KB |
Output is correct |
8 |
Correct |
161 ms |
14852 KB |
Output is correct |
9 |
Correct |
155 ms |
14756 KB |
Output is correct |
10 |
Correct |
157 ms |
14720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
11964 KB |
Output is correct |
2 |
Correct |
110 ms |
12056 KB |
Output is correct |
3 |
Correct |
114 ms |
12084 KB |
Output is correct |
4 |
Correct |
108 ms |
12128 KB |
Output is correct |
5 |
Correct |
158 ms |
12032 KB |
Output is correct |
6 |
Correct |
107 ms |
11980 KB |
Output is correct |
7 |
Correct |
107 ms |
12144 KB |
Output is correct |
8 |
Correct |
155 ms |
12092 KB |
Output is correct |
9 |
Correct |
164 ms |
11976 KB |
Output is correct |
10 |
Correct |
107 ms |
12132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
200 ms |
11912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
11848 KB |
Output is correct |
2 |
Correct |
162 ms |
14880 KB |
Output is correct |
3 |
Correct |
155 ms |
14948 KB |
Output is correct |
4 |
Correct |
153 ms |
14864 KB |
Output is correct |
5 |
Correct |
155 ms |
14820 KB |
Output is correct |
6 |
Correct |
162 ms |
14728 KB |
Output is correct |
7 |
Correct |
163 ms |
14652 KB |
Output is correct |
8 |
Correct |
161 ms |
14852 KB |
Output is correct |
9 |
Correct |
155 ms |
14756 KB |
Output is correct |
10 |
Correct |
157 ms |
14720 KB |
Output is correct |
11 |
Correct |
105 ms |
11964 KB |
Output is correct |
12 |
Correct |
110 ms |
12056 KB |
Output is correct |
13 |
Correct |
114 ms |
12084 KB |
Output is correct |
14 |
Correct |
108 ms |
12128 KB |
Output is correct |
15 |
Correct |
158 ms |
12032 KB |
Output is correct |
16 |
Correct |
107 ms |
11980 KB |
Output is correct |
17 |
Correct |
107 ms |
12144 KB |
Output is correct |
18 |
Correct |
155 ms |
12092 KB |
Output is correct |
19 |
Correct |
164 ms |
11976 KB |
Output is correct |
20 |
Correct |
107 ms |
12132 KB |
Output is correct |
21 |
Incorrect |
200 ms |
11912 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |