結果
問題 | No.1826 Fruits Collecting |
ユーザー | tenten |
提出日時 | 2022-02-15 11:14:52 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,420 ms / 2,000 ms |
コード長 | 2,582 bytes |
コンパイル時間 | 3,080 ms |
コンパイル使用メモリ | 83,044 KB |
実行使用メモリ | 69,612 KB |
最終ジャッジ日時 | 2024-06-29 07:05:46 |
合計ジャッジ時間 | 38,427 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 87 ms
38,604 KB |
testcase_01 | AC | 129 ms
39,324 KB |
testcase_02 | AC | 126 ms
39,316 KB |
testcase_03 | AC | 148 ms
41,056 KB |
testcase_04 | AC | 99 ms
38,200 KB |
testcase_05 | AC | 655 ms
52,132 KB |
testcase_06 | AC | 891 ms
56,128 KB |
testcase_07 | AC | 737 ms
53,404 KB |
testcase_08 | AC | 223 ms
45,464 KB |
testcase_09 | AC | 907 ms
55,556 KB |
testcase_10 | AC | 701 ms
53,888 KB |
testcase_11 | AC | 654 ms
51,160 KB |
testcase_12 | AC | 426 ms
50,540 KB |
testcase_13 | AC | 287 ms
45,296 KB |
testcase_14 | AC | 389 ms
49,528 KB |
testcase_15 | AC | 1,388 ms
64,692 KB |
testcase_16 | AC | 1,305 ms
61,708 KB |
testcase_17 | AC | 1,195 ms
62,168 KB |
testcase_18 | AC | 1,346 ms
64,496 KB |
testcase_19 | AC | 1,364 ms
64,500 KB |
testcase_20 | AC | 1,360 ms
61,240 KB |
testcase_21 | AC | 1,297 ms
62,776 KB |
testcase_22 | AC | 1,286 ms
63,380 KB |
testcase_23 | AC | 1,355 ms
64,376 KB |
testcase_24 | AC | 1,290 ms
61,444 KB |
testcase_25 | AC | 54 ms
37,056 KB |
testcase_26 | AC | 54 ms
37,236 KB |
testcase_27 | AC | 54 ms
37,028 KB |
testcase_28 | AC | 53 ms
37,076 KB |
testcase_29 | AC | 53 ms
37,040 KB |
testcase_30 | AC | 407 ms
50,584 KB |
testcase_31 | AC | 562 ms
50,256 KB |
testcase_32 | AC | 633 ms
53,620 KB |
testcase_33 | AC | 1,319 ms
68,436 KB |
testcase_34 | AC | 1,296 ms
67,856 KB |
testcase_35 | AC | 496 ms
51,472 KB |
testcase_36 | AC | 1,420 ms
67,944 KB |
testcase_37 | AC | 1,137 ms
69,612 KB |
testcase_38 | AC | 785 ms
59,404 KB |
testcase_39 | AC | 682 ms
63,892 KB |
testcase_40 | AC | 770 ms
69,052 KB |
testcase_41 | AC | 429 ms
50,472 KB |
testcase_42 | AC | 178 ms
42,328 KB |
testcase_43 | AC | 53 ms
37,020 KB |
testcase_44 | AC | 52 ms
37,092 KB |
testcase_45 | AC | 52 ms
36,816 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); ArrayList<Fruit> fruits = new ArrayList<>(); TreeMap<Integer, Integer> compress = new TreeMap<>(); for (int i = 0; i < n; i++) { Fruit f = new Fruit(sc.nextInt(), sc.nextInt(), sc.nextInt()); if (f.enable()) { fruits.add(f); compress.put(f.right, null); } } Collections.sort(fruits); int idx = 1; for (int x : compress.keySet()) { compress.put(x, idx++); } long ans = 0; TreeMap<Integer, Long> maxes = new TreeMap<>(); maxes.put(0, 0L); for (Fruit f : fruits) { Integer position = compress.get(f.right); long next = maxes.floorEntry(position).getValue() + f.value; ans = Math.max(ans, next); maxes.put(position, next); while ((position = maxes.higherKey(position)) != null) { if (maxes.get(position) > next) { break; } maxes.remove(position); } } System.out.println(ans); } static class Fruit implements Comparable<Fruit> { int left; int right; int value; public Fruit(int t, int x, int value) { left = t + x; right = t - x; this.value = value; } public int compareTo(Fruit another) { if (left == another.left) { return right - another.right; } else { return left - another.left; } } public boolean enable() { return left >= 0 && right >= 0; } public String toString() { return left + ":" + right + ":" + value; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }