| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1290652 | thuy_k31 | Feast (NOI19_feast) | C++20 | 63 ms | 5088 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(), v.end()
const int N = 1e6 + 9;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
int n, k;
int a[N];
long long pref[N];
pair <long long, long long> dp[2];
pair <long long, long long> cal (long long val)
{
dp[1] = {0, 0};
dp[0] = {-INF, -INF};
for (int i = 1; i <= n; ++i) {
dp[0] = max(dp[0], {dp[1].first - pref[i - 1] - val, dp[1].second});
dp[1] = max(dp[1], {dp[0].first + pref[i], dp[0].second - 1});
}
return dp[1];
}
signed main()
{
#define task "task"
if (fopen(task".inp","r"))
{
freopen (task".inp","r",stdin);
freopen (task".out","w",stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
}
long long lo = -1e15 - 3, hi = 1e15 + 3;
long long ans = -INF;
long long pos = 0;
while (lo <= hi) {
long long mid = (lo + hi) >> 1;
pair <long long, long long> cur = cal(mid);
if (-cur.second <= k) {
hi = mid - 1;
ans = max(ans, cur.first + k * mid);
}
else lo = mid + 1;
}
cout << ans;
}
/**
**/
컴파일 시 표준 에러 (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... | ||||
