Submission #1017473

#TimeUsernameProblemLanguageResultExecution timeMemory
1017473vjudge1Feast (NOI19_feast)C++14
100 / 100
112 ms14012 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define ull unsigned long long #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define taskname "" using namespace std; ll n,k,i,l,r,mid,answer=-1e18,dp[300009][2],a[300009],cnt[300009][2],sum; pll ans; pll check(ll v){ dp[1][0]=0; dp[1][1]=a[1]-v; cnt[1][0]=0; cnt[1][1]=1; for(i=2;i<=n;i++){ if(dp[i-1][1]<dp[i-1][0]){ dp[i][0]=dp[i-1][0]; cnt[i][0]=cnt[i-1][0]; }else{ dp[i][0]=dp[i-1][1]; cnt[i][0]=cnt[i-1][1]; } if(dp[i-1][1]+a[i]<dp[i-1][0]+a[i]-v){ dp[i][1]=dp[i-1][0]+a[i]-v; cnt[i][1]=cnt[i-1][0]+1; }else{ dp[i][1]=dp[i-1][1]+a[i]; cnt[i][1]=cnt[i-1][1]; } }pll res={dp[n][1],cnt[n][1]}; pll result={dp[n][0],cnt[n][0]}; res=max(res,result); return res; } int main() { if (fopen(taskname".inp","r")) { freopen(taskname".inp","r",stdin); freopen(taskname".out","w",stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>k; for(i=1;i<=n;i++) cin>>a[i]; l=0;r=1e18; while(l<=r){ mid=(l+r)/2; ans=check(mid); if(ans.se<=k){ answer=max(answer,ans.fi+mid*ans.se); r=mid-1; }else l=mid+1; }cout<<answer; return 0; }

Compilation message (stderr)

feast.cpp: In function 'int main()':
feast.cpp:40:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   freopen(taskname".inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:41:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   freopen(taskname".out","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...