Submission #361881

#TimeUsernameProblemLanguageResultExecution timeMemory
361881kimbj0709Feast (NOI19_feast)C++14
100 / 100
281 ms10756 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define f first #define s second int n,k; vector<int> vect1; pair<int,int> find(int val){ vector<int> dp(n,0); vector<int> take(n,0); int currmin = 0; int currtake = 0; for(int i=0;i<n;i++){ if(i!=0){ dp[i] = dp[i-1]; take[i] = take[i-1]; } if(vect1[i]-currmin-val>dp[i]){ dp[i] = vect1[i]-currmin-val; take[i] = currtake+1; } if(vect1[i]-dp[i]<currmin){ currmin = vect1[i]-dp[i]; currtake = take[i]; } } return {dp[n-1],take[n-1]}; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin >> n >> k; int input; for(int i=0;i<n;i++){ cin >> input; vect1.push_back(input); } for(int i=1;i<n;i++){ vect1[i] += vect1[i-1]; } int lo = 0,hi = 10e15; while(lo+1!=hi){ int mid = (lo+hi)/2; if(find(mid).s>=k){ lo = mid; } else{ hi = mid; } } //cout << lo << " " << hi << endl; cout << find(lo).f+lo*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...