結果
問題 |
No.2028 Even Choice
|
ユーザー |
|
提出日時 | 2022-12-30 22:11:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 688 bytes |
コンパイル時間 | 1,644 ms |
コンパイル使用メモリ | 169,632 KB |
実行使用メモリ | 17,536 KB |
最終ジャッジ日時 | 2024-11-25 20:47:39 |
合計ジャッジ時間 | 19,514 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 TLE * 5 |
ソースコード
#include <bits/stdc++.h> #define forn(i,s,t) for(int i=(s); i<=(t); ++i) #define form(i,s,t) for(int i=(s); i>=(t); --i) #define rep(i,s,t) for(int i=(s); i<(t); ++i) using namespace std; typedef long long i64; const int N = 2e5 + 5; int n, k; i64 ans, sum, a[N]; multiset<int> S; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> k; forn (i ,1, n) cin >> a[i]; form (i, n, 1) { if (!(i & 1) && S.size() == k - 1) ans = max(ans, sum + a[i]); if (S.size() < k - 1) S.insert(a[i]), sum += a[i]; else if (*S.begin() < a[i]) { sum -= *S.begin(), S.erase(S.begin()); S.insert(a[i]), sum += a[i]; } } cout << ans << '\n'; return 0; } /* */