結果
問題 |
No.2028 Even Choice
|
ユーザー |
|
提出日時 | 2022-07-03 00:56:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 100 ms / 2,000 ms |
コード長 | 695 bytes |
コンパイル時間 | 3,985 ms |
コンパイル使用メモリ | 231,016 KB |
実行使用メモリ | 7,144 KB |
最終ジャッジ日時 | 2024-06-24 21:43:41 |
合計ジャッジ時間 | 7,104 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using mint = modint998244353; using ll = long long; #define all(x) x.begin(), x.end() #define rep(i, n) for (int i = 0; i < n; i++) int main(void) { int n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll summ = 0; ll ans = 0; priority_queue<ll, vector<ll>, greater<ll>> q; for (int i = n - 1; i >= 0; i--){ if(i % 2){ ans = max(ans, summ + a[i]); } q.push(a[i]); summ += a[i]; if(q.size() >= k){ summ -= q.top(); q.pop(); } } cout << ans << endl; return 0; }