結果

問題 No.674 n連勤
ユーザー tentententen
提出日時 2021-12-06 14:06:22
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,799 bytes
コンパイル時間 3,238 ms
コンパイル使用メモリ 75,064 KB
実行使用メモリ 59,192 KB
最終ジャッジ日時 2023-09-21 15:16:45
合計ジャッジ時間 7,921 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,456 KB
testcase_01 AC 45 ms
49,436 KB
testcase_02 AC 45 ms
49,348 KB
testcase_03 WA -
testcase_04 AC 44 ms
49,500 KB
testcase_05 AC 46 ms
49,696 KB
testcase_06 AC 46 ms
50,060 KB
testcase_07 WA -
testcase_08 AC 44 ms
47,856 KB
testcase_09 AC 45 ms
49,340 KB
testcase_10 AC 46 ms
49,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 244 ms
55,492 KB
testcase_14 AC 238 ms
55,560 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0