Submission #1025978

#TimeUsernameProblemLanguageResultExecution timeMemory
1025978ZicrusFeast (NOI19_feast)C++17
12 / 100
123 ms5700 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]; 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)

feast.cpp: In function 'int main()':
feast.cpp:49:10: warning: variable 's' set but not used [-Wunused-but-set-variable]
   49 |     auto s = solve(l);
      |          ^
#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...