# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1017653 |
2024-07-09T09:20:17 Z |
vjudge1 |
Feast (NOI19_feast) |
C++17 |
|
97 ms |
12120 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> A(n + 1);
for (int i = 1; i <= n; i++) {
cin >> A[i];
}
int l = 0, r = 1e18, res = 0;
while (l <= r) {
int md = (l + r) / 2;
vector<array<array<int, 2>, 2>> dp(n + 1);
for (int i = 1; i <= n; i++) {
if (dp[i - 1][0][0] - md + A[i] > dp[i][1][0]) {
dp[i][1][0] = dp[i - 1][0][0] - md + A[i];
dp[i][1][1] = dp[i - 1][0][1] + 1;
}
if (dp[i - 1][1][0] + A[i] > dp[i][1][0]) {
dp[i][1][0] = dp[i - 1][1][0] + A[i];
dp[i][1][1] = dp[i - 1][1][1];
}
if (dp[i - 1][0][0] > dp[i][0][0]) {
dp[i][0][0] = dp[i - 1][0][0];
dp[i][0][1] = dp[i - 1][0][1];
}
if (dp[i - 1][1][0] > dp[i][0][0]) {
dp[i][0][0] = dp[i - 1][1][0];
dp[i][0][1] = dp[i - 1][1][1];
}
}
if (dp.back()[0][0] < dp.back()[1][0]) {
swap(dp.back()[0], dp.back()[1]);
}
if (dp.back()[0][1] <= k) {
r = md - 1, res = max(res, dp.back()[0][0] + md * dp.back()[0][1]);
}
else if (dp.back()[0][1] > k){
l = md + 1;
}
}
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
11828 KB |
Output is correct |
2 |
Correct |
87 ms |
12004 KB |
Output is correct |
3 |
Correct |
96 ms |
12120 KB |
Output is correct |
4 |
Correct |
84 ms |
12020 KB |
Output is correct |
5 |
Correct |
84 ms |
11996 KB |
Output is correct |
6 |
Correct |
82 ms |
11724 KB |
Output is correct |
7 |
Correct |
84 ms |
11776 KB |
Output is correct |
8 |
Correct |
88 ms |
12056 KB |
Output is correct |
9 |
Correct |
91 ms |
11804 KB |
Output is correct |
10 |
Correct |
83 ms |
11876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
78 ms |
11904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
97 ms |
12068 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
11828 KB |
Output is correct |
2 |
Correct |
87 ms |
12004 KB |
Output is correct |
3 |
Correct |
96 ms |
12120 KB |
Output is correct |
4 |
Correct |
84 ms |
12020 KB |
Output is correct |
5 |
Correct |
84 ms |
11996 KB |
Output is correct |
6 |
Correct |
82 ms |
11724 KB |
Output is correct |
7 |
Correct |
84 ms |
11776 KB |
Output is correct |
8 |
Correct |
88 ms |
12056 KB |
Output is correct |
9 |
Correct |
91 ms |
11804 KB |
Output is correct |
10 |
Correct |
83 ms |
11876 KB |
Output is correct |
11 |
Incorrect |
78 ms |
11904 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |