結果
問題 | No.2808 Concentration |
ユーザー |
![]() |
提出日時 | 2024-07-17 13:21:01 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,668 bytes |
コンパイル時間 | 3,045 ms |
コンパイル使用メモリ | 81,740 KB |
実行使用メモリ | 117,300 KB |
最終ジャッジ日時 | 2024-07-17 13:22:13 |
合計ジャッジ時間 | 60,774 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 WA * 52 |
ソースコード
import java.io.*;import java.util.*;import java.util.function.*;import java.util.stream.*;public class Main {static long[] dp;static List<Speech> speeches = new ArrayList<>();static int wake;static int sleep;static TreeMap<Integer, Integer> compress = new TreeMap<>();public static void main(String[] args) throws Exception {Scanner sc = new Scanner();int n = sc.nextInt();wake = sc.nextInt();sleep = sc.nextInt();for (int i = 0; i < n; i++) {Speech current = new Speech(sc.nextInt(), sc.nextInt(), sc.nextInt());if (current.length() <= wake) {speeches.add(current);}}Collections.sort(speeches);for (int i = 0; i < speeches.size(); i++) {compress.put(speeches.get(i).end, i);}compress.put(Integer.MIN_VALUE, -1);dp = new long[speeches.size()];Arrays.fill(dp, -1);System.out.println(dfw(speeches.size() - 1));}static long dfw(int idx) {if (idx < 0) {return 0;}if (dp[idx] < 0) {dp[idx] = Math.max(dfw(idx - 1), dfw(compress.floorEntry(speeches.get(idx).start - sleep).getValue()) + speeches.get(idx).value);}return dp[idx];}static class Speech implements Comparable<Speech> {int start;int end;int value;public Speech(int start, int end, int value) {this.start = start;this.end = end;this.value = value;}public int compareTo(Speech another) {return end - another.end;}public int length() {return end - start;}}}class Scanner {BufferedReader br;StringTokenizer st = new StringTokenizer("");StringBuilder sb = new StringBuilder();public Scanner() {try {br = new BufferedReader(new InputStreamReader(System.in));} catch (Exception e) {}}public int nextInt() {return Integer.parseInt(next());}public long nextLong() {return Long.parseLong(next());}public double nextDouble() {return Double.parseDouble(next());}public String next() {try {while (!st.hasMoreTokens()) {st = new StringTokenizer(br.readLine());}} catch (Exception e) {e.printStackTrace();} finally {return st.nextToken();}}}