Submission #1017575

#TimeUsernameProblemLanguageResultExecution timeMemory
1017575ara_araFeast (NOI19_feast)C++17
100 / 100
136 ms12172 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int inf=1e18; const int maxn=3e5+5; int n,k; int a[maxn]; pair<int,int> alien(int lambda){ pair<int,int> dp[n+5][2]={}; dp[0][1].first=-inf; for(int i=1;i<=n;i++){ dp[i][0]=max(dp[i-1][0],dp[i-1][1]); pair<int,int> p1={dp[i-1][0].first+a[i]-lambda,dp[i-1][0].second+1}; pair<int,int> p2={dp[i-1][1].first+a[i],dp[i-1][1].second}; dp[i][1]=max(p1,p2); } return max(dp[n][1],dp[n][0]); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i]; int l=0,r=inf; while(l<r){ int lambda=(l+r+1)>>1; pair<int,int> tmp=alien(lambda); if(tmp.second>=k) l=lambda; else r=lambda-1; } cout<<alien(l).first+k*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...