結果

問題 No.2028 Even Choice
ユーザー XDXD
提出日時 2022-12-30 22:11:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 688 bytes
コンパイル時間 1,871 ms
コンパイル使用メモリ 168,352 KB
実行使用メモリ 14,308 KB
最終ジャッジ日時 2023-08-17 03:16:27
合計ジャッジ時間 8,865 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
14,084 KB
testcase_01 AC 121 ms
11,832 KB
testcase_02 AC 72 ms
8,140 KB
testcase_03 AC 84 ms
14,308 KB
testcase_04 AC 75 ms
12,832 KB
testcase_05 AC 19 ms
5,404 KB
testcase_06 AC 69 ms
7,988 KB
testcase_07 AC 22 ms
5,716 KB
testcase_08 AC 29 ms
5,184 KB
testcase_09 AC 65 ms
8,872 KB
testcase_10 AC 23 ms
6,304 KB
testcase_11 AC 10 ms
4,380 KB
testcase_12 AC 5 ms
4,384 KB
testcase_13 AC 86 ms
11,548 KB
testcase_14 AC 13 ms
4,384 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

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