結果

問題 No.2028 Even Choice
ユーザー ks2mks2m
提出日時 2022-08-05 22:17:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 457 ms / 2,000 ms
コード長 957 bytes
コンパイル時間 5,409 ms
コンパイル使用メモリ 75,740 KB
実行使用メモリ 74,996 KB
最終ジャッジ日時 2023-10-13 23:28:23
合計ジャッジ時間 11,218 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 457 ms
74,996 KB
testcase_01 AC 404 ms
72,508 KB
testcase_02 AC 443 ms
73,152 KB
testcase_03 AC 343 ms
73,296 KB
testcase_04 AC 331 ms
73,784 KB
testcase_05 AC 200 ms
58,576 KB
testcase_06 AC 454 ms
73,416 KB
testcase_07 AC 212 ms
56,596 KB
testcase_08 AC 327 ms
66,224 KB
testcase_09 AC 416 ms
67,380 KB
testcase_10 AC 175 ms
58,600 KB
testcase_11 AC 187 ms
58,116 KB
testcase_12 AC 131 ms
55,460 KB
testcase_13 AC 361 ms
73,532 KB
testcase_14 AC 235 ms
56,452 KB
testcase_15 AC 44 ms
49,452 KB
testcase_16 AC 44 ms
49,588 KB
testcase_17 AC 45 ms
49,800 KB
testcase_18 AC 49 ms
49,464 KB
testcase_19 AC 49 ms
47,724 KB
testcase_20 AC 55 ms
49,756 KB
testcase_21 AC 55 ms
49,760 KB
testcase_22 AC 51 ms
50,132 KB
testcase_23 AC 44 ms
49,640 KB
testcase_24 AC 45 ms
49,400 KB
testcase_25 AC 43 ms
49,560 KB
testcase_26 AC 44 ms
49,448 KB
testcase_27 AC 44 ms
49,716 KB
testcase_28 AC 256 ms
65,124 KB
testcase_29 AC 211 ms
60,908 KB
testcase_30 AC 197 ms
55,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] a = new int[n + 1];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		PriorityQueue<Integer> que = new PriorityQueue<>();
		long val = 0;
		long ans = 0;
		for (int i = n / 2 * 2 - 1; i > 0; i -= 2) {
			val += a[i];
			if (i < n - 1) {
				que.add(a[i + 1]);
				val += a[i + 1];
			}
			if (que.size() > k - 1) {
				int x = que.poll();
				val -= x;
			}
			ans = Math.max(ans, val);
			que.add(a[i]);
			if (que.size() > k - 1) {
				int x = que.poll();
				val -= x;
			}
		}
		System.out.println(ans);
	}
}
0