結果
問題 | No.2139 K Consecutive Sushi |
ユーザー | tenten |
提出日時 | 2023-07-06 08:39:44 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 615 ms / 2,000 ms |
コード長 | 2,813 bytes |
コンパイル時間 | 2,909 ms |
コンパイル使用メモリ | 92,280 KB |
実行使用メモリ | 60,908 KB |
最終ジャッジ日時 | 2024-11-27 19:56:15 |
合計ジャッジ時間 | 13,880 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
36,816 KB |
testcase_01 | AC | 45 ms
36,616 KB |
testcase_02 | AC | 46 ms
37,112 KB |
testcase_03 | AC | 544 ms
59,556 KB |
testcase_04 | AC | 602 ms
57,664 KB |
testcase_05 | AC | 615 ms
59,388 KB |
testcase_06 | AC | 531 ms
60,256 KB |
testcase_07 | AC | 613 ms
60,908 KB |
testcase_08 | AC | 462 ms
55,460 KB |
testcase_09 | AC | 484 ms
56,692 KB |
testcase_10 | AC | 482 ms
55,864 KB |
testcase_11 | AC | 492 ms
56,632 KB |
testcase_12 | AC | 448 ms
56,116 KB |
testcase_13 | AC | 47 ms
36,892 KB |
testcase_14 | AC | 45 ms
36,756 KB |
testcase_15 | AC | 47 ms
36,808 KB |
testcase_16 | AC | 46 ms
37,000 KB |
testcase_17 | AC | 44 ms
37,004 KB |
testcase_18 | AC | 81 ms
37,960 KB |
testcase_19 | AC | 81 ms
38,316 KB |
testcase_20 | AC | 79 ms
37,948 KB |
testcase_21 | AC | 48 ms
36,808 KB |
testcase_22 | AC | 89 ms
38,776 KB |
testcase_23 | AC | 173 ms
42,772 KB |
testcase_24 | AC | 289 ms
46,432 KB |
testcase_25 | AC | 394 ms
53,044 KB |
testcase_26 | AC | 168 ms
43,684 KB |
testcase_27 | AC | 270 ms
47,488 KB |
testcase_28 | AC | 259 ms
47,064 KB |
testcase_29 | AC | 196 ms
46,696 KB |
testcase_30 | AC | 329 ms
49,776 KB |
testcase_31 | AC | 510 ms
56,980 KB |
testcase_32 | AC | 217 ms
45,496 KB |
testcase_33 | AC | 418 ms
59,800 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(); long total = 0; int[] values = new int[n + 2]; for (int i = 1; i <= n; i++) { values[i] = sc.nextInt(); total += values[i]; } Sushi[] sushies = new Sushi[n + 2]; sushies[0] = new Sushi(0, 0); TreeSet<Sushi> mins = new TreeSet<>(); mins.add(sushies[0]); for (int i = 1; i <= n + 1; i++) { sushies[i] = new Sushi(i, mins.first().value + values[i]); mins.add(sushies[i]); if (i - k >= 0) { mins.remove(sushies[i - k]); } } System.out.println(total - sushies[n + 1].value); } static class Sushi implements Comparable<Sushi> { int idx; long value; public Sushi(int idx, long value) { this.idx = idx; this.value = value; } public int hashCode() { return idx; } public int compareTo(Sushi another) { if (value == another.value) { return idx - another.idx; } else if (value < another.value) { return -1; } else { return 1; } } public boolean equals(Object o) { return hashCode() == o.hashCode(); } } } 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(); } }