# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
996992 | blackslex | Feast (NOI19_feast) | C++17 | 113 ms | 11612 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
int n, k;
int main() {
scanf("%d %d", &n, &k);
vector<ll> a(n + 5), pref(n + 5);
vector<pii> dp(n + 5);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), pref[i] = pref[i - 1] + a[i];
auto get = [&] (ll x) {
pii cmx(0, 0);
for (int i = 1; i <= n; i++) {
dp[i] = max(dp[i - 1], {cmx.first + pref[i] - x, cmx.second - 1});
cmx = max(cmx, {dp[i].first - pref[i], dp[i].second});
}
return pii(dp[n].first, -dp[n].second);
};
ll l = 0, r = 3e14;
while (l <= r) {
ll mid = (l + r) >> 1LL;
if (get(mid).second <= k) r = mid - 1;
else l = mid + 1;
}
printf("%lld", get(l).first + l * k);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |