# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
902474 |
2024-01-10T13:06:57 Z |
thinknoexit |
Feast (NOI19_feast) |
C++17 |
|
76 ms |
10324 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int a[300300], n;
ll qs[300300];
ll dp[300300];
int cnt[300300];
void cal(ll mid) {
pair<ll, int> mx(0ll, 0);
for (int i = 1;i <= n;i++) {
dp[i] = dp[i - 1];
cnt[i] = cnt[i - 1];
if (qs[i] + mx.first - mid > dp[i]) {
dp[i] = qs[i] + mx.first - mid;
cnt[i] = mx.second + 1;
}
mx = max(mx, { dp[i] - qs[i], cnt[i] });
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int k;
cin >> n >> k;
for (int i = 1;i <= n;i++) {
cin >> a[i];
qs[i] = qs[i - 1] + a[i];
}
ll l = 0, r = 1e13;
while (l < r) {
ll mid = l + (r - l) / 2;
cal(mid);
if (cnt[n] <= k) r = mid;
else l = mid + 1;
}
cal(l);
cout << dp[n] + 1ll * cnt[n] * k;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
10000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
8280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
76 ms |
10324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
10000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |