結果
問題 | No.180 美しいWhitespace (2) |
ユーザー |
![]() |
提出日時 | 2015-03-08 15:30:04 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 220 ms / 5,000 ms |
コード長 | 896 bytes |
コンパイル時間 | 2,270 ms |
コンパイル使用メモリ | 77,660 KB |
実行使用メモリ | 56,880 KB |
最終ジャッジ日時 | 2024-06-24 15:55:48 |
合計ジャッジ時間 | 10,055 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
package beautifulws; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for(int i=0;i<n;i++) { a[i] = sc.nextInt(); b[i] = sc.nextInt(); } System.out.println(solve(n,a,b)); } public static long solve(int n,int[] a,int[] b) { long left = 1; long right = 1_000_000_010; while(left + 1 < right) { long x = (left + right) >> 1; if (f(x-1,n,a,b) > f(x,n,a,b)) { left = x; }else{ right = x; } } return left; } public static long f(long x,int n,int[] a,int[] b) { 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 h = a[i] + b[i] * x; max = Math.max(h, max); min = Math.min(h, min); } return max - min; } }