結果

問題 No.817 Coin donation
ユーザー takeya_okinotakeya_okino
提出日時 2019-08-07 22:00:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 831 ms / 2,000 ms
コード長 819 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 73,964 KB
実行使用メモリ 67,252 KB
最終ジャッジ日時 2023-09-25 23:18:23
合計ジャッジ時間 10,562 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,916 KB
testcase_01 AC 128 ms
55,924 KB
testcase_02 AC 139 ms
55,808 KB
testcase_03 AC 158 ms
56,140 KB
testcase_04 AC 134 ms
55,860 KB
testcase_05 AC 237 ms
59,220 KB
testcase_06 AC 370 ms
60,668 KB
testcase_07 AC 407 ms
60,600 KB
testcase_08 AC 703 ms
64,620 KB
testcase_09 AC 434 ms
60,168 KB
testcase_10 AC 786 ms
66,924 KB
testcase_11 AC 808 ms
66,672 KB
testcase_12 AC 831 ms
67,252 KB
testcase_13 AC 124 ms
55,748 KB
testcase_14 AC 126 ms
55,832 KB
testcase_15 AC 125 ms
55,724 KB
権限があれば一括ダウンロードができます

ソースコード

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