| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1368576 | 12345678 | Feast (NOI19_feast) | C++17 | 89 ms | 9804 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll nx=3e5+5, inf=1e18;
ll n, k, a[nx], qs[nx];
pair<ll, ll> solve(ll lambda)
{
pair<ll, ll> mx;
vector<pair<ll, ll>> dp(n+1, {-inf, 0});
dp[0]={0, 0};
for (int i=1; i<=n; i++)
{
mx=max(mx, {dp[i-1].first-qs[i], dp[i-1].second});
dp[i]=max(dp[i-1], {mx.first+qs[i]-lambda, mx.second+1});
}
return dp[n];
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>k;
for (int i=1; i<=n; i++) cin>>a[i], qs[i]=qs[i-1]+a[i];
ll l=0, r=3e14;
while (l<r)
{
ll md=(l+r+1)/2;
if (solve(md).second>=k) l=md;
else r=md-1;
}
cout<<solve(l).first+l*k;
}
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
