# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1070826 |
2024-08-22T19:12:51 Z |
TAhmed33 |
Feast (NOI19_feast) |
C++ |
|
99 ms |
12152 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e5 + 25;
ll a[MAXN], n, k;
pair <ll, ll> eval (ll mid) {
pair <ll, ll> dp[n + 1][2];
dp[1][0] = {0, 0};
dp[1][1] = {a[1] - mid, 1};
for (int i = 2; i <= n; i++) {
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
pair <ll, ll> g = {dp[i - 1][0].first + a[i] - mid, dp[i - 1][0].second + 1};
pair <ll, ll> h = {dp[i - 1][1].first + a[i], dp[i - 1][1].second};
dp[i][1] = max(g, h);
}
return max(dp[n][0], dp[n][1]);
}
void solve () {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
ll l = 0, r = 1e18, ans = -1;
while (l <= r) {
ll mid = (l + r) / 2;
if (eval(mid).second >= k) {
l = mid + 1; ans = mid;
} else {
r = mid - 1;
}
}
cout << max(0ll, eval(ans).first + ans * k) << '\n';
}
signed main () {
ios::sync_with_stdio(0); cin.tie(0);
int tc = 1; //cin >> tc;
while (tc--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
11600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
11860 KB |
Output is correct |
2 |
Correct |
65 ms |
12120 KB |
Output is correct |
3 |
Correct |
60 ms |
11864 KB |
Output is correct |
4 |
Incorrect |
66 ms |
11856 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
11868 KB |
Output is correct |
2 |
Correct |
97 ms |
11860 KB |
Output is correct |
3 |
Correct |
98 ms |
12008 KB |
Output is correct |
4 |
Correct |
94 ms |
11900 KB |
Output is correct |
5 |
Correct |
94 ms |
12120 KB |
Output is correct |
6 |
Correct |
96 ms |
12076 KB |
Output is correct |
7 |
Correct |
99 ms |
12124 KB |
Output is correct |
8 |
Correct |
95 ms |
11860 KB |
Output is correct |
9 |
Correct |
97 ms |
12152 KB |
Output is correct |
10 |
Correct |
98 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
11600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |