# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
440034 |
2021-07-01T13:28:32 Z |
dongliu0426 |
Feast (NOI19_feast) |
C++14 |
|
158 ms |
10820 KB |
#include <bits/stdc++.h>
using namespace std;
#define N 300000
#define INF ((long long) 300000 * 1000000000)
int n, k, a[N + 1];
pair<long long, int> dp[N + 1][2];
template<class T, class U> T lastTrue(T lo, T hi, U f) {
assert(lo <= hi); --lo; /* assuming f is decreasing */
while (lo < hi) { /* find last index such that f is true */
T mid = lo + (hi - lo + 1) / 2;
f(mid) ? lo = mid : hi = mid - 1;
} return lo;
}
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i)
scanf("%d", a + i);
auto check = [&](long long penalty) {
dp[0][0] = {0, 0}, dp[0][1] = {-INF, 0};
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][1].first + a[i], dp[i - 1][1].second),
make_pair(dp[i - 1][0].first + a[i] - penalty, dp[i - 1][0].second + 1));
}
return max(dp[n][0], dp[n][1]).second >= k;
};
long long penalty = lastTrue<long long>(0, INF, check);
check(penalty);
printf("%lld\n", (long long) penalty * k + max(dp[n][0], dp[n][1]).first);
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
feast.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d", a + i);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
104 ms |
10512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
10588 KB |
Output is correct |
2 |
Correct |
97 ms |
10780 KB |
Output is correct |
3 |
Correct |
103 ms |
10692 KB |
Output is correct |
4 |
Incorrect |
107 ms |
10672 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
126 ms |
10720 KB |
Output is correct |
2 |
Correct |
126 ms |
10692 KB |
Output is correct |
3 |
Correct |
132 ms |
10800 KB |
Output is correct |
4 |
Correct |
130 ms |
10568 KB |
Output is correct |
5 |
Correct |
123 ms |
10692 KB |
Output is correct |
6 |
Correct |
122 ms |
10644 KB |
Output is correct |
7 |
Correct |
158 ms |
10712 KB |
Output is correct |
8 |
Correct |
129 ms |
10688 KB |
Output is correct |
9 |
Correct |
128 ms |
10820 KB |
Output is correct |
10 |
Correct |
131 ms |
10756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
104 ms |
10512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |