Submission #587994

#TimeUsernameProblemLanguageResultExecution timeMemory
587994sofapudenFeast (NOI19_feast)C++14
0 / 100
1092 ms26756 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll mn = -(1ll<<60); void solve(){ int n, k; cin >> n >> k; vector<ll> v(n); for(auto &x : v)cin >> x; ll l = 0, r = (1ll<<60), bes = 0; while(l<=r){ ll m = (l+r)>>1; vector<vector<pair<ll,ll>>> dp(n,vector<pair<ll,ll>>(2)); dp[0][0] = {0,0}; dp[0][1] = {-m+v[0],0}; for(int i = 1; i < n; ++i){ dp[i][0] = max(dp[i-1][0],{dp[i-1][1].first,dp[i-1][1].second+1}); dp[i][1] = max(dp[i-1][1],{dp[i-1][0].first-m,dp[i-1][0].second}); dp[i][1].first+=v[i]; } pair<ll,ll> b = max(dp[n-1][0], dp[n-1][1]); if(b.second >= m){ bes = b.first + m*k; l = m+1; } else{ r = m-1; } } cout << bes << '\n'; } int main(){ solve(); }
#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...