Submission #778853

#TimeUsernameProblemLanguageResultExecution timeMemory
778853dooweyFeast (NOI19_feast)C++14
59 / 100
100 ms7348 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int N = (int)3e5 + 10; const ll inf = (ll)1e18; ll P[N]; pii dp[N]; int n; void compute(ll penalty){ for(int i = 1 ; i <= n; i ++ ){ dp[i]=mp(-inf,0); } pii cur=mp(dp[0].fi-P[0]-penalty, 1); for(int i = 1; i <= n; i ++ ){ dp[i]=max(dp[i-1],mp(cur.fi+P[i],cur.se)); cur=max(cur,mp(dp[i].fi-P[i]-penalty,dp[i].se+1)); } } int main(){ fastIO; int k; cin >> n >> k; int taken = 0; for(int i = 1; i <= n; i ++ ){ cin >> P[i]; if(P[i] >= 0) taken ++ ; P[i]+=P[i-1]; } k=min(k,taken); ll lf = 0ll; ll rf = (ll)1e18; ll mid; ll penalty; while(lf < rf){ mid = (lf + rf) / 2; compute(mid); if(dp[n].se > k){ lf=mid+1; } else{ rf=mid; } } compute(lf); cout << dp[n].fi + k * 1ll * lf << "\n"; return 0; }

Compilation message (stderr)

feast.cpp: In function 'int main()':
feast.cpp:45:8: warning: unused variable 'penalty' [-Wunused-variable]
   45 |     ll penalty;
      |        ^~~~~~~
#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...