結果

問題 No.2028 Even Choice
ユーザー polyesterpolyester
提出日時 2022-08-08 19:35:17
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 3,147 ms
コンパイル使用メモリ 133,888 KB
実行使用メモリ 6,828 KB
最終ジャッジ日時 2023-10-19 08:15:10
合計ジャッジ時間 7,239 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
5,780 KB
testcase_01 AC 94 ms
6,828 KB
testcase_02 AC 98 ms
5,780 KB
testcase_03 AC 92 ms
6,828 KB
testcase_04 AC 93 ms
6,828 KB
testcase_05 AC 21 ms
4,348 KB
testcase_06 AC 86 ms
5,608 KB
testcase_07 AC 25 ms
4,348 KB
testcase_08 AC 59 ms
4,532 KB
testcase_09 AC 68 ms
5,332 KB
testcase_10 AC 25 ms
4,348 KB
testcase_11 AC 18 ms
4,348 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 70 ms
6,476 KB
testcase_14 AC 28 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 54 ms
4,348 KB
testcase_29 AC 36 ms
4,348 KB
testcase_30 AC 25 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 0;
  ll sum = 0;
  priority_queue<ll, vector<ll>, greater<ll>> pq;
  for(int i = n - 1; i >= 0; i--) {
    if(i % 2 == 1) {
      ans = max(ans, sum + a[i]);
    }
    sum += a[i];
    pq.push(a[i]);
    if(pq.size() >= k) {
      sum -= pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
  return 0;
}
0