結果
問題 |
No.1037 exhausted
|
ユーザー |
![]() |
提出日時 | 2021-01-30 12:17:52 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,137 bytes |
コンパイル時間 | 2,756 ms |
コンパイル使用メモリ | 85,100 KB |
実行使用メモリ | 59,536 KB |
最終ジャッジ日時 | 2024-06-28 00:25:02 |
合計ジャッジ時間 | 8,279 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 5 |
ソースコード
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, Integer> base = new TreeMap<>(); base.put(volume, 0); int prev = 0; for (int i = 0; i < n; i++) { int x = sc.nextInt(); int v = sc.nextInt(); int w = sc.nextInt(); TreeMap<Integer, Integer> next = new TreeMap<>(); for (int y : base.keySet()) { int 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); } }