結果

問題 No.180 美しいWhitespace (2)
ユーザー t8m8⛄️
提出日時 2015-04-07 08:41:37
言語 Java
(openjdk 23)
結果
AC  
実行時間 208 ms / 5,000 ms
コード長 1,357 bytes
コンパイル時間 4,092 ms
コンパイル使用メモリ 78,084 KB
実行使用メモリ 44,388 KB
最終ジャッジ日時 2024-07-04 03:34:13
合計ジャッジ時間 9,562 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class No180 {
    
    static final Scanner in = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);

    static void solve() {
        n = in.nextInt();
        a = new int[n];
        b = new int[n];
        for (int i=0; i<n; i++) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
        }

        long l = 1, r = 1500000000;
        while (l+1 < r) {
            long x = (l+r)/2;
            if (f(x-1) > f(x)) l = x;
            else r = x;
        }
        out.println(l);
    }

    static int n;
    static int[] a, b;

    static long f(long x) {
        if (x <=0) return Long.MAX_VALUE;
        long max = Long.MIN_VALUE;
        long min = Long.MAX_VALUE;
        for (int i=0; i<n; i++) {
            long y = a[i] + b[i]*x;
            max = max(max,y);
            min = min(min,y);
        }
        return max - min;
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        solve();
        out.flush();

        long end = System.currentTimeMillis();
        //trace(end-start + "ms");
        in.close();
        out.close();
    }

    static void trace(Object... o) { System.out.println(deepToString(o));}
}
0