結果

問題 No.1037 exhausted
ユーザー tentententen
提出日時 2021-01-30 12:19:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 373 ms / 2,000 ms
コード長 2,134 bytes
コンパイル時間 2,350 ms
コンパイル使用メモリ 76,196 KB
実行使用メモリ 61,916 KB
最終ジャッジ日時 2023-09-10 09:02:11
合計ジャッジ時間 8,370 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,320 KB
testcase_01 AC 121 ms
55,944 KB
testcase_02 AC 121 ms
55,700 KB
testcase_03 AC 124 ms
56,004 KB
testcase_04 AC 122 ms
55,844 KB
testcase_05 AC 123 ms
55,972 KB
testcase_06 AC 125 ms
55,396 KB
testcase_07 AC 126 ms
56,316 KB
testcase_08 AC 122 ms
56,392 KB
testcase_09 AC 123 ms
55,368 KB
testcase_10 AC 124 ms
56,300 KB
testcase_11 AC 126 ms
56,000 KB
testcase_12 AC 320 ms
61,300 KB
testcase_13 AC 300 ms
60,292 KB
testcase_14 AC 324 ms
61,916 KB
testcase_15 AC 326 ms
58,460 KB
testcase_16 AC 342 ms
61,416 KB
testcase_17 AC 373 ms
61,460 KB
testcase_18 AC 314 ms
61,296 KB
testcase_19 AC 312 ms
61,520 KB
testcase_20 AC 232 ms
59,160 KB
testcase_21 AC 232 ms
60,016 KB
testcase_22 AC 234 ms
58,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int volume = sc.nextInt();
        int length = sc.nextInt();
        TreeMap<Integer, Long> base = new TreeMap<>();
        base.put(volume, 0L);
        int prev = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int v = sc.nextInt();
            long w = sc.nextInt();
            TreeMap<Integer, Long> next = new TreeMap<>();
            for (int y : base.keySet()) {
                long value = base.get(y);
                int none = y - x + prev;
                if (none >= 0) {
                    Integer key = next.ceilingKey(none);
                    if (key == null || next.get(key) > value) {
                        next.put(none, value);
                        key = none;
                        while ((key = next.lowerKey(key)) != null) {
                            if (next.get(key) >= value) {
                                next.remove(key);
                            } else {
                                break;
                            }
                        }
                    }
                    int full = Math.min(volume, none + v);
                    key = next.ceilingKey(full);
                    if (key == null || next.get(key) > value + w) {
                        next.put(full, value + w);
                        key = full;
                        while ((key = next.lowerKey(key)) != null) {
                            if (next.get(key) >= value + w) {
                                next.remove(key);
                            } else {
                                break;
                            }
                        }
                    }
                }
            }
            prev = x;
            base = next;
        }
        for (int y : base.keySet()) {
            if (y - length + prev >= 0) {
                System.out.println(base.get(y));
                return;
            }
        }
        System.out.println(-1);
    }
}
0