| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1290632 | Bui_Quoc_Cuong | Feast (NOI19_feast) | C++20 | 115 ms | 21560 KiB |
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ll long long
#define ALL(x) (x).begin(), (x).end()
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define fi first
#define se second
using namespace std;
const int N = 3e5 + 5;
int n, k;
int a[N];
pair <ll, int> dp[N][4];
pair <ll, int> calc(ll lamda) {
dp[1][0] = {0, 0};
dp[1][1] = {a[1] - lamda, 1};
for(int i = 2; i <= n; i++) {
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
dp[i][1] = max(make_pair(dp[i - 1][0].fi + a[i] - lamda, dp[i - 1][0].se + 1),
make_pair(dp[i - 1][1].fi + a[i], dp[i - 1][1].se));
}
return max(dp[n][0], dp[n][1]);
}
void solve() {
cin >> n >> k;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
ll sum = 0;
FOR(i, 1, n) if(a[i] > 0) sum+= a[i];
ll l = 1, r = sum, ans = 0;
while(l <= r) {
int mid = (l + r) / 2;
if(calc(mid).se >= k) ans = mid, l = mid + 1;
else r = mid - 1;
}
cout << max(1ll * 0, 1ll * ans * k + calc(ans).fi);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
file("feast");
solve();
cerr << "Time used: " << TIME << " s.\n";
return (0 ^ 0);
}
컴파일 시 표준 에러 (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... | ||||
