제출 #1269774

#제출 시각아이디문제언어결과실행 시간메모리
1269774ducdevFeast (NOI19_feast)C++17
59 / 100
1096 ms10848 KiB
// Author: 4uckd3v - Nguyen Cao Duc #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX_N = 1e6; const int MOD = 1e9 + 7; const ll INF = 1e18; int n, k; int a[MAX_N + 5]; ll pref[MAX_N + 5]; ll getSum(int l, int r) { return pref[r] - pref[l - 1]; }; namespace SUBTASK_3456 { const int LIM = 1e8; bool checkSubtask() { return 1LL * n * k <= LIM; }; void Solve() { vector<ll> cur(n + 5, -INF), nxt(n + 5, -INF), mx(n + 5); for (int i = 0; i <= n; i++) cur[i] = 0; nxt[0] = 0; ll res = 0; for (int i = 1; i <= k; i++) { mx[i - 1] = -INF; for (int r = i; r <= n; r++) { mx[r] = max(mx[r - 1], cur[r - 1] - pref[r - 1]); nxt[r] = max(nxt[r - 1], mx[r] + pref[r]); }; for (int r = i; r <= n; r++) { cur[r] = nxt[r]; nxt[r] = -INF; }; res = max(res, cur[n]); }; cout << res << '\n'; }; }; // namespace SUBTASK_3456 int main() { ios_base::sync_with_stdio(0); cin.tie(0); if (fopen("MAIN.INP", "r")) { freopen("MAIN.INP", "r", stdin); freopen("MAIN.OUT", "w", stdout); }; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; pref[i] = pref[i - 1] + a[i]; }; SUBTASK_3456::Solve(); };

컴파일 시 표준 에러 (stderr) 메시지

feast.cpp: In function 'int main()':
feast.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen("MAIN.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen("MAIN.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...