Submission #676480

#TimeUsernameProblemLanguageResultExecution timeMemory
676480penguin133Feast (NOI19_feast)C++17
100 / 100
152 ms15100 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #define getchar_unlocked _getchar_nolock int n, k, A[300005]; pi dp[300005][2]; int ans; int c(int x){ dp[0][0] = {0, 0}; dp[0][1] = {-1e18, 0}; for(int i=1;i<=n;i++){ dp[i][0] = max(dp[i-1][0], dp[i-1][1]); dp[i][1] = max({make_pair(dp[i-1][0].fi + A[i] - x, dp[i-1][0].se + 1), make_pair(dp[i-1][1].fi + A[i], dp[i-1][1].se)}); } pi tmp = max(dp[n][0], dp[n][1]); if(tmp.se <= k)ans = max(ans, tmp.fi + tmp.se * x); cerr << x << " " << tmp.fi << " " << tmp.se << '\n'; return tmp.se; } void solve(){ cin >> n >> k; for(int i=1;i<=n;i++)cin >> A[i]; int lo = 0, hi = 1e15; while(lo <= hi){ int mid = (lo + hi) >> 1; if(c(mid) >= k)lo = mid + 1; else hi = mid - 1; } cout << ans; } main(){ ios::sync_with_stdio(0);cin.tie(0); int tc = 1; //cin >> tc; while(tc--){ solve(); } }

Compilation message (stderr)

feast.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 | main(){
      | ^~~~
#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...