# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1103044 |
2024-10-19T15:23:24 Z |
rastervc |
Feast (NOI19_feast) |
C++17 |
|
1000 ms |
11004 KB |
#include <iostream>
constexpr long long INF = 1e18;
constexpr int MAX_N = 3e5 + 5;
int N, K, a[MAX_N];
std::pair<long long, int> dp[MAX_N][2];
std::pair<long long, int> check(long long lambda) {
dp[1][0] = { 0, 0 };
dp[1][1] = { a[1] - lambda, 1 };
for (int i = 2; i <= N; ++i) {
dp[i][0] = std::max(dp[i - 1][0], dp[i - 1][1]);
dp[i][1] = std::max(
std::make_pair(dp[i - 1][0].first + a[i] - lambda, dp[i - 1][0].second + 1),
std::make_pair(dp[i - 1][1].first + a[i], dp[i - 1][1].second)
);
}
return std::max(dp[N][0], dp[N][1]);
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> N >> K;
for (int i = 1; i <= N; ++i)
std::cin >> a[i];
long long l = 0, r = INF, ans = 0;
while (l < r) {
long long mid = (l + r) >> 1;
if (check(mid).second >= K) l = mid;
else r = mid - 1;
}
std::cout << check(l).first + l * K;
return 0;
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:31:31: warning: unused variable 'ans' [-Wunused-variable]
31 | long long l = 0, r = INF, ans = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
10832 KB |
Output is correct |
2 |
Correct |
54 ms |
10832 KB |
Output is correct |
3 |
Correct |
55 ms |
10832 KB |
Output is correct |
4 |
Correct |
56 ms |
10832 KB |
Output is correct |
5 |
Correct |
59 ms |
10832 KB |
Output is correct |
6 |
Correct |
53 ms |
10984 KB |
Output is correct |
7 |
Correct |
51 ms |
11004 KB |
Output is correct |
8 |
Correct |
53 ms |
10828 KB |
Output is correct |
9 |
Correct |
58 ms |
10832 KB |
Output is correct |
10 |
Correct |
52 ms |
10832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1056 ms |
10832 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1069 ms |
10832 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2556 KB |
Output is correct |
5 |
Execution timed out |
1092 ms |
2396 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2556 KB |
Output is correct |
5 |
Execution timed out |
1092 ms |
2396 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2556 KB |
Output is correct |
5 |
Execution timed out |
1092 ms |
2396 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
10832 KB |
Output is correct |
2 |
Correct |
54 ms |
10832 KB |
Output is correct |
3 |
Correct |
55 ms |
10832 KB |
Output is correct |
4 |
Correct |
56 ms |
10832 KB |
Output is correct |
5 |
Correct |
59 ms |
10832 KB |
Output is correct |
6 |
Correct |
53 ms |
10984 KB |
Output is correct |
7 |
Correct |
51 ms |
11004 KB |
Output is correct |
8 |
Correct |
53 ms |
10828 KB |
Output is correct |
9 |
Correct |
58 ms |
10832 KB |
Output is correct |
10 |
Correct |
52 ms |
10832 KB |
Output is correct |
11 |
Execution timed out |
1056 ms |
10832 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |