結果
| 問題 |
No.1037 exhausted
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-01-30 12:19:59 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 402 ms / 2,000 ms |
| コード長 | 2,134 bytes |
| コンパイル時間 | 2,274 ms |
| コンパイル使用メモリ | 79,284 KB |
| 実行使用メモリ | 48,540 KB |
| 最終ジャッジ日時 | 2024-06-28 00:27:49 |
| 合計ジャッジ時間 | 8,219 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
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);
}
}
tenten