Submission #1026006

#TimeUsernameProblemLanguageResultExecution timeMemory
1026006ZicrusFeast (NOI19_feast)C++17
100 / 100
106 ms5724 KiB
#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] - p; ll ps = 0; ll psSeg = 1; for (int i = 1; i < n; i++) { ll tdp = dp, tdpSeg = dpSeg, tps = ps, tpsSeg = psSeg; if (tdpSeg > tdp) { dp = tdpSeg; ps = tpsSeg; } if (tdp - p > tdpSeg) { dpSeg = tdp - p; psSeg = tps + 1; } dpSeg += a[i]; } if (dpSeg > dp) { dp = dpSeg; ps = psSeg; } return {dp, ps}; } int main() { ios::sync_with_stdio(0); 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; ll bestAns = 0; ll pen = 0; while (l <= r) { ll mid = pen = (l + r) / 2; auto best = solve(mid); bestK = best.second; bestAns = best.first; if (bestK > k) { l = mid + 1; } else { if (l == r) break; r = mid; } } ll val = bestAns + k * pen; cout << val; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...