| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1351608 | PakinDioxide | Feast (NOI19_feast) | C++17 | 118 ms | 2760 KiB |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mxN = 3e5+5;
ll a[mxN];
int main() {
int n, k; cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
auto calc = [&] (ll l) {
pair <ll, ll> dp[2];
dp[0] = make_pair(0, 0);
dp[1] = make_pair(a[1] - l, 1);
for (int i = 2; i <= n; i++) {
pair <ll, ll> x, y;
x = max(dp[0], dp[1]);
y = max(
make_pair(dp[0].first + a[i] - l, dp[0].second + 1),
make_pair(dp[1].first + a[i], dp[1].second)
);
dp[0] = x, dp[1] = y;
}
return max(dp[0], dp[1]);
};
ll L = 0, R = 3e14, ans = 0;
while (L <= R) {
ll x = L + (R-L)/2;
if (calc(x).second >= k) L = x+1, ans = x;
else R = x-1;
}
cout << calc(ans).first + k * ans << '\n';
}
| # | 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... | ||||
