結果

問題 No.817 Coin donation
ユーザー takeya_okinotakeya_okino
提出日時 2019-08-07 22:00:50
言語 Java
(openjdk 23)
結果
AC  
実行時間 717 ms / 2,000 ms
コード長 819 bytes
コンパイル時間 2,239 ms
コンパイル使用メモリ 77,344 KB
実行使用メモリ 57,772 KB
最終ジャッジ日時 2024-07-18 18:53:13
合計ジャッジ時間 9,893 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long k = sc.nextLong();
    long[] a = new long[n];
    long[] b = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
      b[i] = sc.nextLong();
    }
    long l = 1;
    long r = (long)Math.pow(10, 9) + 1;
    long ans = 0;
    while(l < r) {
      long med = (l + r) / 2;
      long t = 0;
      for(int i = 0; i < n; i++) {
        if(a[i] <= med) {
          if(b[i] <= med) {
            t += (b[i] - a[i] + 1);
          } else {
            t += (med - a[i] + 1);
          }
        }
      }
      if(t >= k) {
        ans = med;
        r = med;
      } else {
        l = med + 1;
      }
    }
    System.out.println(ans);
  }
}
0