# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1258817 | phtung | Feast (NOI19_feast) | C++20 | 1096 ms | 327680 KiB |
#include <bits/stdc++.h>
using namespace std;
#define name "IO"
#define int long long
const int inf = 1e18 + 7;
const int maxn = 3e5 + 5;
int n, k, a[maxn];
int Pow(int x, int y)
{
int ans = 1;
while (y > 0)
{
if (y & 1) ans = ans * x;
y /= 2;
x = x * x;
}
return ans;
}
void solve()
{
cin >> n >> k;
vector<int> pre(n + 1, 0);
for(int i = 1; i <= n; i++)
{
cin >> a[i];
pre[i] = pre[i - 1] + a[i];
}
vector<vector<int>> dp(k + 1, vector<int>(n + 1, 0));
for(int i = 1; i <= k; i++)
{
for(int j = 1; j <= n; j++)
{
int mx = 0;
for(int l = 0; l < j; l++)
{
mx = max(mx, dp[i - 1][l] - pre[l]);
}
dp[i][j] = max(dp[i][j - 1], pre[j] + mx);
}
}
int res = 0;
for(int i = 1; i <= n; i++) res = max(res, dp[k][i]);
cout << res << "\n";
}
signed main()
{
if (fopen (name".INP", "r"))
{
freopen (name".INP", "r", stdin);
freopen (name".OUT", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
clock_t start = clock();
int t = 1;
while(t--) solve();
std::cerr << "Time: " << clock() - start << "ms\n";
return 0;
}
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... |