# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1103149 | joyboy23ti | Feast (NOI19_feast) | C++14 | 488 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define N 300005
#define pb push_back
#define mod 1000000007
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int>
#define INF 1e18
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define FORD(i, a, b) for(int i = a; i >= b; --i)
using namespace std;
int n, k, a[N], pre[N], dp[5500][5500];
void proc()
{
cin >> n >> k;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) pre[i] = pre[i - 1] + a[i];
FOR(i, 1, k)
{
int mx = -INF;
FOR(j, 1, n)
{
mx = max(mx, dp[j - 1][i - 1] - pre[j - 1]);
dp[j][i] = max(dp[j - 1][i], mx + pre[j]);
}
}
cout << dp[n][k];
}
int32_t main() {
if(fopen("test.inp", "r"))
{
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T; T = 1;
//cin >> T;
while (T--) proc();
}
Compilation message (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... |