結果

問題 No.777 再帰的ケーキ
ユーザー tentententen
提出日時 2023-06-16 13:27:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,063 ms / 2,000 ms
コード長 2,704 bytes
コンパイル時間 2,606 ms
コンパイル使用メモリ 90,824 KB
実行使用メモリ 83,360 KB
最終ジャッジ日時 2023-09-06 12:37:12
合計ジャッジ時間 13,801 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
47,752 KB
testcase_01 AC 41 ms
49,720 KB
testcase_02 AC 42 ms
49,868 KB
testcase_03 AC 43 ms
49,768 KB
testcase_04 AC 43 ms
49,704 KB
testcase_05 AC 42 ms
49,624 KB
testcase_06 AC 43 ms
49,740 KB
testcase_07 AC 43 ms
49,680 KB
testcase_08 AC 42 ms
49,980 KB
testcase_09 AC 42 ms
49,724 KB
testcase_10 AC 44 ms
49,788 KB
testcase_11 AC 42 ms
49,688 KB
testcase_12 AC 43 ms
49,800 KB
testcase_13 AC 43 ms
49,852 KB
testcase_14 AC 45 ms
49,924 KB
testcase_15 AC 43 ms
47,668 KB
testcase_16 AC 43 ms
50,008 KB
testcase_17 AC 43 ms
49,680 KB
testcase_18 AC 45 ms
49,772 KB
testcase_19 AC 43 ms
49,924 KB
testcase_20 AC 44 ms
49,872 KB
testcase_21 AC 135 ms
53,860 KB
testcase_22 AC 137 ms
53,404 KB
testcase_23 AC 81 ms
52,072 KB
testcase_24 AC 87 ms
51,652 KB
testcase_25 AC 134 ms
54,416 KB
testcase_26 AC 136 ms
54,088 KB
testcase_27 AC 113 ms
53,392 KB
testcase_28 AC 1,063 ms
64,564 KB
testcase_29 AC 988 ms
63,764 KB
testcase_30 AC 1,043 ms
64,072 KB
testcase_31 AC 1,045 ms
63,784 KB
testcase_32 AC 672 ms
83,360 KB
testcase_33 AC 349 ms
61,280 KB
testcase_34 AC 432 ms
63,532 KB
testcase_35 AC 1,012 ms
64,264 KB
testcase_36 AC 690 ms
81,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        Cake[] cakes = new Cake[n];
        for (int i = 0; i < n; i++) {
            cakes[i] = new Cake(sc.nextInt(), sc.nextInt(), sc.nextInt());
        }
        Arrays.sort(cakes);
        TreeMap<Integer, Long> ans = new TreeMap<>();
        ans.put(Integer.MAX_VALUE, 0L);
        for (Cake x : cakes) {
            long next = ans.higherEntry(x.b).getValue() + x.value;
            if (ans.getOrDefault(x.b, 0L) >= next) {
                continue;
            }
            ans.put(x.b, next);
            Integer key = x.b;
            while ((key = ans.lowerKey(key)) != null) {
                if (ans.get(key) > next) {
                    break;
                }
                ans.remove(key);
            }
        }
        System.out.println(ans.firstEntry().getValue());
    }
    
    static class Cake implements Comparable<Cake> {
        int a;
        int b;
        int value;
        
        public Cake(int a, int b, int value) {
            this.a = a;
            this.b = b;
            this.value = value;
        }
        
        public int compareTo(Cake another) {
            if (a == another.a) {
                return b - another.b;
            } else {
                return another.a - a;
            }
        }
    }
}
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();
    }
    
}
0