# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
439908 |
2021-07-01T07:31:44 Z |
dongliu0426 |
Feast (NOI19_feast) |
C++14 |
|
217 ms |
13908 KB |
#include <bits/stdc++.h>
using namespace std;
#define N 300000
#define INF 0x3f3f3f3f3f3f3f3f
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);
long long sum = 0;
for (int i = 1; i <= n; ++i)
scanf("%d", a + i), sum += a[i];
auto check = [&](long long penalty) {
dp[0][0] = {0, 0}, dp[0][1] = {-INF, 0};
for (int i = 1; i <= n; ++i) {
pair<long long, int> last = max(dp[i - 1][0], dp[i - 1][1]);
dp[i][0] = max(make_pair(last.first - penalty, last.second + 1), last);
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", max(dp[n][0], dp[n][1]).first + penalty * k);
}
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:22:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d", a + i), sum += a[i];
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
196 ms |
10508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
10512 KB |
Output is correct |
2 |
Correct |
190 ms |
11844 KB |
Output is correct |
3 |
Correct |
187 ms |
11612 KB |
Output is correct |
4 |
Incorrect |
185 ms |
11792 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
192 ms |
10724 KB |
Output is correct |
2 |
Correct |
215 ms |
13536 KB |
Output is correct |
3 |
Correct |
202 ms |
13712 KB |
Output is correct |
4 |
Correct |
197 ms |
13764 KB |
Output is correct |
5 |
Correct |
212 ms |
13732 KB |
Output is correct |
6 |
Correct |
189 ms |
13680 KB |
Output is correct |
7 |
Correct |
215 ms |
13840 KB |
Output is correct |
8 |
Correct |
215 ms |
13712 KB |
Output is correct |
9 |
Correct |
202 ms |
13792 KB |
Output is correct |
10 |
Correct |
217 ms |
13908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
196 ms |
10508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |