# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1025978 | Zicrus | Feast (NOI19_feast) | C++17 | 123 ms | 5700 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;
typedef long long ll;
ll n, k;
vector<ll> a;
pair<ll, ll> solve(ll p) {
ll dp = 0;
ll dpSeg = a[0];
ll ps = 0;
ll psSeg = 1;
for (int i = 1; i < n; i++) {
ps = (dp - ps * p) > (dpSeg - psSeg * p) ? ps : psSeg;
dp = (dp - ps * p) > (dpSeg - psSeg * p) ? dp : dpSeg;
if (dp - ((ps+1) * p) > dpSeg) {
dpSeg = dp - p + a[i];
psSeg = ps + 1;
}
else {
dpSeg += a[i];
}
}
ll val = (dp - ps * p) > (dpSeg - psSeg * p) ? (dp - ps * p) : (dpSeg - psSeg * p);
ll pss = dp == dpSeg ? min(ps, psSeg) : (dp > dpSeg ? ps : psSeg);
return {val, pss};
}
int main() {
cin >> n >> k;
a = vector<ll>(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ll l = 0, r = 1ll << 50;
ll bestK = 1ll << 50;
while (l < r) {
ll mid = (l + r) / 2;
bestK = solve(mid).second;
if (bestK > k) {
l = mid + 1;
}
else {
r = mid;
}
}
auto s = solve(l);
ll val = solve(l).first + k * l;
cout << val;
}
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... |