結果
問題 | No.674 n連勤 |
ユーザー |
![]() |
提出日時 | 2021-12-06 14:06:22 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,799 bytes |
コンパイル時間 | 3,018 ms |
コンパイル使用メモリ | 79,424 KB |
実行使用メモリ | 58,880 KB |
最終ジャッジ日時 | 2024-07-07 09:01:41 |
合計ジャッジ時間 | 6,757 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 WA * 9 |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); long d = sc.nextLong(); int n = sc.nextInt(); TreeMap<Long, Long> days = new TreeMap<>(); StringBuilder sb = new StringBuilder(); long max = 0; for (int i = 0; i < n; i++) { long left = sc.nextLong(); long right = sc.nextLong(); Long prev = days.floorKey(left); if (prev != null && days.get(prev) >= left - 1) { left = prev; right = Math.max(right, days.get(prev)); } days.put(left, right); Long next; while ((next = days.higherKey(left)) != null) { if (right + 1 < next) { break; } right = Math.max(right, days.get(next)); days.remove(next); } max = Math.max(max, right - left + 1); sb.append(max).append("\n"); } System.out.print(sb); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); 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 String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }