# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
981171 |
2024-05-13T01:10:59 Z |
beaboss |
Feast (NOI19_feast) |
C++14 |
|
10 ms |
2652 KB |
// Source: https://oj.uz/problem/view/NOI19_feast
//
#include "bits/stdc++.h"
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; i++)
typedef pair<int, int> pii;
#define s second
#define f first
const int N = 1e5 + 10;
int a[N];
pii dp[N][2];
int n, k;
pii solve(int l) {
dp[0][0] = {0, 0};
dp[0][1] = {a[0] - l, 1};
FOR(i, 1, n) {
dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
dp[i][1] = max(make_pair(dp[i-1][0].f + a[i] - l, dp[i-1][0].s + 1), make_pair(dp[i-1][1].f + a[i], dp[i-1][1].s));
}
return max(dp[n-1][1], dp[n-1][0]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
FOR(i, 0 ,n) cin >> a[i];
int lo = 0;
int hi = 1e9;
while (lo < hi) {
int m = (lo + hi + 1)/2;
pii res = solve(m);
// cout << res.s << k << endl;
if (res.s >= k) lo = m;
else hi = m -1;
}
// cout << lo << solve(lo).f << endl;
cout << solve(lo).f + k * lo << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
2396 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
1884 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
2652 KB |
Execution killed with signal 11 |
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 |
Runtime error |
9 ms |
2396 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |