結果

問題 No.1137 Circles
ユーザー face4
提出日時 2020-08-04 22:38:28
言語 Java
(openjdk 23)
結果
AC  
実行時間 590 ms / 2,000 ms
コード長 1,208 bytes
コンパイル時間 2,577 ms
コンパイル使用メモリ 78,788 KB
実行使用メモリ 62,608 KB
最終ジャッジ日時 2024-09-14 22:16:02
合計ジャッジ時間 12,269 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;

enum type {in, out};

class Point implements Comparable<Point>{
    int x;
    type t;
    Point(int x, type t){
        this.x = x;
        this.t = t;
    }
    @Override
    public int compareTo(Point p){
        if(this.x != p.x){
            return x-p.x;
        }else{
            return this.t == type.out ? -1 : 1;
        }
    }
}
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        ArrayList<Point> a = new ArrayList<Point>(2*n);
        for(int i = 0; i < n; i++){
            String[] line = br.readLine().split(" ");
            int x = Integer.parseInt(line[0]);
            int r = Integer.parseInt(line[1]);
            a.add(new Point(x-r, type.in));
            a.add(new Point(x+r, type.out));
        }
        Collections.sort(a);
        int ret = 0, now = 0;
        for(int i = 0; i < 2*n; i++){
            now += a.get(i).t==type.in ? 1 : -1;
            ret = Math.max(ret, now);
        }
        System.out.println(ret);
    }
}
0