# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
739788 |
2023-05-11T09:53:07 Z |
NeroZein |
Feast (NOI19_feast) |
C++17 |
|
107 ms |
21448 KB |
#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 300005;
int n, k;
int a[N];
pair<long long,int> dp[N][2];
pair<long long,int> solve (long long cost) {
dp[0][0] = {0LL, 0};
dp[0][1] = {-1e15, -N};
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][0].first + a[i] - cost, dp[i - 1][0].second + 1),
make_pair(dp[i - 1][1].first + a[i], dp[i - 1][1].second));
}
return max(dp[n][0], dp[n][1]);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
long long l = 0, r = (long long) N * 1e9;
while (l < r) {
long long mid = (l + r + 1) >> 1;
if (solve(mid).second > k) {
l = mid;
} else {
r = mid - 1;
}
}
assert(solve(l).second > k);
cout << solve(l).first + l * k << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
99 ms |
21196 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
10576 KB |
Output is correct |
2 |
Correct |
84 ms |
10856 KB |
Output is correct |
3 |
Correct |
87 ms |
10504 KB |
Output is correct |
4 |
Runtime error |
94 ms |
21448 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
10752 KB |
Output is correct |
2 |
Correct |
99 ms |
10572 KB |
Output is correct |
3 |
Correct |
104 ms |
10608 KB |
Output is correct |
4 |
Correct |
100 ms |
10624 KB |
Output is correct |
5 |
Correct |
100 ms |
10700 KB |
Output is correct |
6 |
Correct |
104 ms |
10696 KB |
Output is correct |
7 |
Correct |
107 ms |
10700 KB |
Output is correct |
8 |
Correct |
97 ms |
10704 KB |
Output is correct |
9 |
Correct |
101 ms |
10816 KB |
Output is correct |
10 |
Correct |
98 ms |
10820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
99 ms |
21196 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |