結果

問題 No.1137 Circles
ユーザー tentententen
提出日時 2022-08-04 15:16:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 699 ms / 2,000 ms
コード長 1,740 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 75,212 KB
実行使用メモリ 55,720 KB
最終ジャッジ日時 2023-10-12 12:52:28
合計ジャッジ時間 12,285 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
33,480 KB
testcase_01 AC 672 ms
54,920 KB
testcase_02 AC 112 ms
36,728 KB
testcase_03 AC 434 ms
48,720 KB
testcase_04 AC 535 ms
51,400 KB
testcase_05 AC 203 ms
42,920 KB
testcase_06 AC 633 ms
53,500 KB
testcase_07 AC 393 ms
47,520 KB
testcase_08 AC 599 ms
52,604 KB
testcase_09 AC 280 ms
46,812 KB
testcase_10 AC 376 ms
47,208 KB
testcase_11 AC 427 ms
48,660 KB
testcase_12 AC 699 ms
55,720 KB
testcase_13 AC 304 ms
45,836 KB
testcase_14 AC 685 ms
54,788 KB
testcase_15 AC 314 ms
45,996 KB
testcase_16 AC 440 ms
48,740 KB
testcase_17 AC 140 ms
38,132 KB
testcase_18 AC 622 ms
53,568 KB
testcase_19 AC 299 ms
46,132 KB
testcase_20 AC 256 ms
44,456 KB
testcase_21 AC 41 ms
33,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] lefts = new int[n];
        int[] rights = new int[n];
        TreeMap<Integer, Integer> compress = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            int r = sc.nextInt();
            lefts[i] = x - r;
            compress.put(lefts[i], null);
            rights[i] = x + r;
            compress.put(rights[i], null);
        }
        int idx = 1;
        for (int x : compress.keySet()) {
            compress.put(x, idx++);
        }
        int[] imos = new int[idx];
        for (int i = 0; i < n; i++) {
            imos[compress.get(lefts[i])]++;
            imos[compress.get(rights[i])]--;
        }
        int max = 0;
        for (int i = 1; i < idx; i++) {
            imos[i] += imos[i - 1];
            max = Math.max(max, imos[i]);
        }
        System.out.println(max);
    }
}

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 {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0