結果

問題 No.2028 Even Choice
ユーザー simansiman
提出日時 2022-08-07 18:05:12
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 722 bytes
コンパイル時間 2,464 ms
コンパイル使用メモリ 132,352 KB
実行使用メモリ 6,796 KB
最終ジャッジ日時 2023-10-17 12:46:58
合計ジャッジ時間 5,408 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
5,748 KB
testcase_01 AC 93 ms
6,796 KB
testcase_02 AC 97 ms
5,748 KB
testcase_03 AC 92 ms
6,796 KB
testcase_04 AC 93 ms
6,796 KB
testcase_05 AC 21 ms
4,348 KB
testcase_06 AC 86 ms
5,576 KB
testcase_07 AC 26 ms
4,348 KB
testcase_08 AC 59 ms
4,500 KB
testcase_09 AC 68 ms
5,300 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,444 KB
testcase_14 AC 27 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 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 1 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 1 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 <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;


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>> pque;

  for (int i = N - 1; i >= 1; --i) {
    ll a = A[i];
    pque.push(a);
    sum += a;

    if (i % 2 == 1) {
      ans = max(ans, sum);
    }

    if (pque.size() >= K) {
      ll v = pque.top();
      sum -= v;
      pque.pop();
    }
  }

  cout << ans << endl;

  return 0;
}
0