結果

問題 No.2028 Even Choice
ユーザー tnakao0123tnakao0123
提出日時 2022-08-13 02:39:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 1,045 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 58,560 KB
実行使用メモリ 15,036 KB
最終ジャッジ日時 2023-10-24 14:12:54
合計ジャッジ時間 3,161 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
10,320 KB
testcase_01 AC 156 ms
12,556 KB
testcase_02 AC 102 ms
8,872 KB
testcase_03 AC 86 ms
15,036 KB
testcase_04 AC 77 ms
13,556 KB
testcase_05 AC 23 ms
5,328 KB
testcase_06 AC 94 ms
8,584 KB
testcase_07 AC 30 ms
5,872 KB
testcase_08 AC 44 ms
5,620 KB
testcase_09 AC 89 ms
9,380 KB
testcase_10 AC 31 ms
6,412 KB
testcase_11 AC 14 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 117 ms
12,104 KB
testcase_14 AC 20 ms
4,356 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 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 31 ms
4,776 KB
testcase_29 AC 21 ms
4,348 KB
testcase_30 AC 14 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2028.cc:  No.2028 Even Choice - yukicoder
 */

#include<cstdio>
#include<set>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;
typedef set<pii> spii;

/* global variables */

int as[MAX_N];
pii ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  for (int i = 0; i < n; i++) ps[i] = pii(as[i], i);
  sort(ps, ps + n, greater<pii>());

  spii q;
  ll maxs = 0, sum = 0;
  for (int i = 1, j = 0; i < n; i += 2) {
    while (! q.empty() && q.begin()->first <= i) {
      sum -= q.begin()->second;
      q.erase(q.begin());
    }

    while (j < n && q.size() < k - 1) {
      if (ps[j].second > i) {
	sum += ps[j].first;
	q.insert(pii(ps[j].second, ps[j].first));
      }
      j++;
    }
    if (q.size() < k - 1) break;

    maxs = max(maxs, sum + as[i]);
  }

  printf("%lld\n", maxs);
  return 0;
}
0