Submission #996992

#TimeUsernameProblemLanguageResultExecution timeMemory
996992blackslexFeast (NOI19_feast)C++17
100 / 100
113 ms11612 KiB
#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)

feast.cpp: In function 'int main()':
feast.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
feast.cpp:13:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), pref[i] = pref[i - 1] + a[i];
      |                                  ~~~~~^~~~~~~~~~~~~~~
#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...