結果
問題 | No.2139 K Consecutive Sushi |
ユーザー | tenten |
提出日時 | 2023-07-06 08:39:44 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 786 ms / 2,000 ms |
コード長 | 2,813 bytes |
コンパイル時間 | 3,136 ms |
コンパイル使用メモリ | 85,312 KB |
実行使用メモリ | 61,100 KB |
最終ジャッジ日時 | 2024-05-05 19:24:39 |
合計ジャッジ時間 | 15,200 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
36,856 KB |
testcase_01 | AC | 55 ms
37,024 KB |
testcase_02 | AC | 55 ms
37,024 KB |
testcase_03 | AC | 779 ms
61,100 KB |
testcase_04 | AC | 713 ms
57,584 KB |
testcase_05 | AC | 783 ms
60,248 KB |
testcase_06 | AC | 679 ms
59,676 KB |
testcase_07 | AC | 786 ms
60,028 KB |
testcase_08 | AC | 503 ms
55,372 KB |
testcase_09 | AC | 535 ms
57,028 KB |
testcase_10 | AC | 576 ms
56,608 KB |
testcase_11 | AC | 540 ms
55,756 KB |
testcase_12 | AC | 536 ms
56,328 KB |
testcase_13 | AC | 57 ms
37,228 KB |
testcase_14 | AC | 57 ms
37,144 KB |
testcase_15 | AC | 58 ms
37,196 KB |
testcase_16 | AC | 57 ms
36,860 KB |
testcase_17 | AC | 60 ms
36,688 KB |
testcase_18 | AC | 97 ms
38,792 KB |
testcase_19 | AC | 98 ms
38,056 KB |
testcase_20 | AC | 92 ms
38,356 KB |
testcase_21 | AC | 58 ms
37,284 KB |
testcase_22 | AC | 106 ms
39,064 KB |
testcase_23 | AC | 191 ms
42,528 KB |
testcase_24 | AC | 357 ms
47,152 KB |
testcase_25 | AC | 472 ms
52,864 KB |
testcase_26 | AC | 191 ms
43,296 KB |
testcase_27 | AC | 315 ms
47,456 KB |
testcase_28 | AC | 319 ms
47,196 KB |
testcase_29 | AC | 221 ms
45,900 KB |
testcase_30 | AC | 375 ms
50,084 KB |
testcase_31 | AC | 652 ms
57,316 KB |
testcase_32 | AC | 229 ms
45,188 KB |
testcase_33 | AC | 495 ms
60,168 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(); } }