結果

問題 No.1826 Fruits Collecting
ユーザー tentententen
提出日時 2022-02-15 11:14:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,483 ms / 2,000 ms
コード長 2,582 bytes
コンパイル時間 3,028 ms
コンパイル使用メモリ 87,504 KB
実行使用メモリ 80,652 KB
最終ジャッジ日時 2023-09-11 16:59:12
合計ジャッジ時間 37,851 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
51,776 KB
testcase_01 AC 116 ms
53,720 KB
testcase_02 AC 118 ms
53,844 KB
testcase_03 AC 133 ms
54,112 KB
testcase_04 AC 85 ms
52,056 KB
testcase_05 AC 634 ms
63,312 KB
testcase_06 AC 901 ms
67,456 KB
testcase_07 AC 675 ms
64,996 KB
testcase_08 AC 210 ms
56,980 KB
testcase_09 AC 871 ms
66,444 KB
testcase_10 AC 690 ms
64,476 KB
testcase_11 AC 664 ms
67,080 KB
testcase_12 AC 403 ms
60,992 KB
testcase_13 AC 265 ms
56,732 KB
testcase_14 AC 368 ms
61,472 KB
testcase_15 AC 1,462 ms
74,708 KB
testcase_16 AC 1,437 ms
75,340 KB
testcase_17 AC 1,241 ms
75,768 KB
testcase_18 AC 1,483 ms
75,148 KB
testcase_19 AC 1,377 ms
72,668 KB
testcase_20 AC 1,281 ms
75,300 KB
testcase_21 AC 1,260 ms
73,272 KB
testcase_22 AC 1,248 ms
73,260 KB
testcase_23 AC 1,334 ms
72,860 KB
testcase_24 AC 1,155 ms
72,648 KB
testcase_25 AC 43 ms
49,628 KB
testcase_26 AC 42 ms
49,984 KB
testcase_27 AC 44 ms
49,984 KB
testcase_28 AC 43 ms
49,684 KB
testcase_29 AC 44 ms
49,900 KB
testcase_30 AC 381 ms
57,548 KB
testcase_31 AC 536 ms
62,760 KB
testcase_32 AC 588 ms
64,620 KB
testcase_33 AC 1,256 ms
79,108 KB
testcase_34 AC 1,124 ms
76,576 KB
testcase_35 AC 448 ms
62,604 KB
testcase_36 AC 1,369 ms
80,652 KB
testcase_37 AC 1,064 ms
79,376 KB
testcase_38 AC 773 ms
68,280 KB
testcase_39 AC 647 ms
75,216 KB
testcase_40 AC 723 ms
78,456 KB
testcase_41 AC 407 ms
62,656 KB
testcase_42 AC 164 ms
54,348 KB
testcase_43 AC 43 ms
49,740 KB
testcase_44 AC 43 ms
50,016 KB
testcase_45 AC 44 ms
49,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0