結果
問題 | No.2028 Even Choice |
ユーザー | tenten |
提出日時 | 2023-03-01 11:12:23 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 393 ms / 2,000 ms |
コード長 | 2,178 bytes |
コンパイル時間 | 5,348 ms |
コンパイル使用メモリ | 86,824 KB |
実行使用メモリ | 65,680 KB |
最終ジャッジ日時 | 2023-10-14 16:02:25 |
合計ジャッジ時間 | 11,021 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 366 ms
64,848 KB |
testcase_01 | AC | 314 ms
63,460 KB |
testcase_02 | AC | 371 ms
63,992 KB |
testcase_03 | AC | 259 ms
65,680 KB |
testcase_04 | AC | 268 ms
65,444 KB |
testcase_05 | AC | 185 ms
56,092 KB |
testcase_06 | AC | 393 ms
61,332 KB |
testcase_07 | AC | 182 ms
56,332 KB |
testcase_08 | AC | 291 ms
58,088 KB |
testcase_09 | AC | 289 ms
58,284 KB |
testcase_10 | AC | 184 ms
55,692 KB |
testcase_11 | AC | 194 ms
54,660 KB |
testcase_12 | AC | 127 ms
54,796 KB |
testcase_13 | AC | 246 ms
60,396 KB |
testcase_14 | AC | 248 ms
56,604 KB |
testcase_15 | AC | 40 ms
49,468 KB |
testcase_16 | AC | 41 ms
49,644 KB |
testcase_17 | AC | 39 ms
47,532 KB |
testcase_18 | AC | 45 ms
49,432 KB |
testcase_19 | AC | 45 ms
49,668 KB |
testcase_20 | AC | 55 ms
49,816 KB |
testcase_21 | AC | 52 ms
50,112 KB |
testcase_22 | AC | 46 ms
49,900 KB |
testcase_23 | AC | 39 ms
49,564 KB |
testcase_24 | AC | 40 ms
49,568 KB |
testcase_25 | AC | 39 ms
49,992 KB |
testcase_26 | AC | 38 ms
49,672 KB |
testcase_27 | AC | 40 ms
49,408 KB |
testcase_28 | AC | 233 ms
57,688 KB |
testcase_29 | AC | 200 ms
56,508 KB |
testcase_30 | AC | 183 ms
56,652 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int k = sc.nextInt(); int[] values = new int[n]; for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); } PriorityQueue<Integer> queue = new PriorityQueue<>(); long total = 0; int current; long ans = 0; for (int i = n - 1; i >= 0; i--) { current = values[i]; if (i % 2 == 1) { while (queue.size() > k - 1) { total -= queue.poll(); } if (queue.size() == k - 1) { ans = Math.max(ans, current + total); } } total += current; queue.add(current); } System.out.println(ans); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }