제출 #1123477

#제출 시각아이디문제언어결과실행 시간메모리
1123477btninhFeast (NOI19_feast)C++17
18 / 100
108 ms10992 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) >> 1LL; if (Calc(mid).se >= k) l = mid + 1; else r = mid - 1; } cout << Calc(r).fi + r * k; }

컴파일 시 표준 에러 (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...