# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1269774 | ducdev | Feast (NOI19_feast) | C++17 | 1096 ms | 10848 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) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |