Submission #1017557

#TimeUsernameProblemLanguageResultExecution timeMemory
1017557vjudge1Feast (NOI19_feast)C++17
100 / 100
957 ms24024 KiB
#include <bits/stdc++.h> using namespace std; #define int long long pair<int,int> solve(int l,int a[],int n){ vector<vector<pair<int,int>>> DP(n,vector<pair<int,int>>(2)); DP[0][0]={0,0}; DP[0][1]={a[0]-l,1}; for(int i=1;i<n;i++){ DP[i][0]=max(DP[i-1][0],DP[i-1][1]); DP[i][1]=max(DP[i-1][1],{DP[i-1][0].first-l,DP[i-1][0].second+1}); DP[i][1].first+=a[i]; } return max(DP[n-1][0],DP[n-1][1]); } signed main() { int n,k; cin >> n >> k; int a[n]; for(int i=0;i<n;i++){ cin >> a[i]; } int low=0,high=1e18; while(low<high){ int mid=(high+low+1)/2; if(solve(mid,a,n).second>=k){ low=mid; } else{ high=mid-1; } } cout << solve(low,a,n).first+low*k; }
#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...