Submission #1123474

#TimeUsernameProblemLanguageResultExecution timeMemory
1123474btninhFeast (NOI19_feast)C++17
100 / 100
139 ms11000 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define TASK "A" const int N = 3e5 + 5; int n, k, a[N]; pair<ll,ll> dp[N][2]; pair<ll,ll> Calc(ll lmd){ dp[1][0] = {0, 0}; dp[1][1] = {a[1] - lmd, 1}; for(int i = 2; i <= n; ++i){ dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]); dp[i][1] = max(make_pair(dp[i - 1][1].fi + a[i], dp[i - 1][1].se), make_pair(dp[i - 1][0].fi + a[i] - lmd, dp[i - 1][0].se + 1)); } return max(dp[n][0], dp[n][1]); } signed main() { if(fopen(TASK".inp", "r")){ freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for(int i = 1; i <= n; ++i) cin >> a[i]; ll l = 0, r = 1e18; while (l < r) { ll mid = (l + r + 1) >> 1LL; if (Calc(mid).se >= k) l = mid; else r = mid - 1; } cout << Calc(l).fi + l * k; }

Compilation message (stderr)

feast.cpp: In function 'int main()':
feast.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...