結果

問題 No.2028 Even Choice
ユーザー SSRSSSRS
提出日時 2022-08-05 21:25:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 485 bytes
コンパイル時間 1,670 ms
コンパイル使用メモリ 169,796 KB
実行使用メモリ 4,936 KB
最終ジャッジ日時 2023-10-13 21:48:07
合計ジャッジ時間 3,919 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
4,584 KB
testcase_01 AC 83 ms
4,916 KB
testcase_02 AC 88 ms
4,588 KB
testcase_03 AC 80 ms
4,936 KB
testcase_04 AC 82 ms
4,860 KB
testcase_05 AC 19 ms
4,352 KB
testcase_06 AC 76 ms
4,380 KB
testcase_07 AC 23 ms
4,348 KB
testcase_08 AC 53 ms
4,352 KB
testcase_09 AC 60 ms
4,364 KB
testcase_10 AC 22 ms
4,348 KB
testcase_11 AC 16 ms
4,348 KB
testcase_12 AC 7 ms
4,356 KB
testcase_13 AC 62 ms
4,684 KB
testcase_14 AC 25 ms
4,352 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,476 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,352 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 48 ms
4,348 KB
testcase_29 AC 32 ms
4,348 KB
testcase_30 AC 21 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  priority_queue<int, vector<int>, greater<int>> pq;
  long long ans = 0;
  long long sum = 0;
  for (int i = N - 1; i >= 0; i--){
    if (i % 2 == 1){
      ans = max(ans, sum + A[i]);
    }
    pq.push(A[i]);
    sum += A[i];
    if (pq.size() >= K){
      sum -= pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}
0