結果

問題 No.2028 Even Choice
ユーザー XDXD
提出日時 2022-12-30 22:13:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 777 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 169,048 KB
実行使用メモリ 14,248 KB
最終ジャッジ日時 2023-08-17 03:19:09
合計ジャッジ時間 5,172 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
9,592 KB
testcase_01 AC 113 ms
11,776 KB
testcase_02 AC 78 ms
8,216 KB
testcase_03 AC 86 ms
14,248 KB
testcase_04 AC 76 ms
12,784 KB
testcase_05 AC 17 ms
5,296 KB
testcase_06 AC 67 ms
7,956 KB
testcase_07 AC 22 ms
5,668 KB
testcase_08 AC 28 ms
5,124 KB
testcase_09 AC 66 ms
8,884 KB
testcase_10 AC 22 ms
6,212 KB
testcase_11 AC 10 ms
4,384 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 94 ms
11,492 KB
testcase_14 AC 13 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 18 ms
4,508 KB
testcase_29 AC 12 ms
4,380 KB
testcase_30 AC 9 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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<i64> S;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> k;
	forn (i ,1, n) cin >> a[i];
	if (k == 1) {
		forn (i, 1, n) if (!(i & 1)) ans = max(ans, a[i]);
		goto END;
	}
	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];
		}
	}
	END:
	cout << ans << '\n';
	return 0;
}
/*
*/
0