結果
| 問題 |
No.2028 Even Choice
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-05 23:05:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 79 ms / 2,000 ms |
| コード長 | 780 bytes |
| コンパイル時間 | 2,197 ms |
| コンパイル使用メモリ | 198,336 KB |
| 最終ジャッジ日時 | 2025-01-30 18:41:26 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <algo/debug.h>
#else
#define debug(...) 42
#endif
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
priority_queue<int, vector<int>, greater<int>> big;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long ans = 0;
long long sum = 0;
for (int i = n - 1; i >= 0; i--) {
if (i % 2 == 1 && big.size() == k - 1) {
ans = max(ans, sum + a[i]);
}
if (big.size() < k - 1) {
big.push(a[i]);
sum += a[i];
} else {
if (!big.empty() && big.top() < a[i]) {
int top = big.top(); big.pop();
big.push(a[i]);
sum += a[i] - top;
}
}
}
cout << ans << '\n';
return 0;
}