# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1100495 |
2024-10-14T06:04:32 Z |
Ryuga_ |
Feast (NOI19_feast) |
C++14 |
|
217 ms |
11004 KB |
/*For today, you happen to be the defeated. But what will you become tomorrow?*/
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 300005;
const ll inf = (1ll << 60);
int arr[N], n, k;
array<ll, 2> dp[N][2];
array<ll, 2> f(ll c) {
for(int i = 0; i <= n; i ++) {
dp[i][0] = {0, 0};
dp[i][1] = {-inf, 0};
}
for(int i = 1; i <= n; i ++) {
dp[i][0] = dp[i - 1][0];
dp[i][1] = {dp[i - 1][1][0] + (ll)arr[i], dp[i - 1][1][1]};
array<ll, 2> cur = {dp[i - 1][0][0] + (ll)arr[i] - c, dp[i - 1][0][1] + 1};
dp[i][1] = max(dp[i][1], cur);
dp[i][0] = max(dp[i][0], dp[i][1]);
}
return dp[n][0];
}
void solve() {
cin >> n >> k;
for(int i = 1; i <= n; i ++) cin >> arr[i];
ll lo = -(1ll << 60), hi = (1ll << 60), ans = 0;
while(lo <= hi) {
ll mid = (lo + hi) / 2;
array<ll, 2> yo = f(mid);
if(yo[1] >= k) {
ans = yo[0] + k * mid;
lo = mid + 1;
}
else {
ans = yo[0] + yo[1] * mid;
hi = mid - 1;
}
}
cout << ans << '\n';
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
10832 KB |
Output is correct |
2 |
Correct |
217 ms |
10832 KB |
Output is correct |
3 |
Correct |
207 ms |
10832 KB |
Output is correct |
4 |
Correct |
200 ms |
10824 KB |
Output is correct |
5 |
Correct |
192 ms |
10832 KB |
Output is correct |
6 |
Correct |
195 ms |
10960 KB |
Output is correct |
7 |
Correct |
190 ms |
10832 KB |
Output is correct |
8 |
Correct |
198 ms |
10824 KB |
Output is correct |
9 |
Correct |
190 ms |
10832 KB |
Output is correct |
10 |
Correct |
214 ms |
10844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
11004 KB |
Output is correct |
2 |
Incorrect |
100 ms |
10832 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
132 ms |
10832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
10832 KB |
Output is correct |
2 |
Correct |
217 ms |
10832 KB |
Output is correct |
3 |
Correct |
207 ms |
10832 KB |
Output is correct |
4 |
Correct |
200 ms |
10824 KB |
Output is correct |
5 |
Correct |
192 ms |
10832 KB |
Output is correct |
6 |
Correct |
195 ms |
10960 KB |
Output is correct |
7 |
Correct |
190 ms |
10832 KB |
Output is correct |
8 |
Correct |
198 ms |
10824 KB |
Output is correct |
9 |
Correct |
190 ms |
10832 KB |
Output is correct |
10 |
Correct |
214 ms |
10844 KB |
Output is correct |
11 |
Correct |
99 ms |
11004 KB |
Output is correct |
12 |
Incorrect |
100 ms |
10832 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |