結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー takeya_okinotakeya_okino
提出日時 2019-08-11 16:26:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 646 ms / 3,000 ms
コード長 1,017 bytes
コンパイル時間 2,040 ms
コンパイル使用メモリ 74,312 KB
実行使用メモリ 63,176 KB
最終ジャッジ日時 2023-10-11 21:16:34
合計ジャッジ時間 10,358 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,508 KB
testcase_01 AC 123 ms
55,856 KB
testcase_02 AC 126 ms
55,840 KB
testcase_03 AC 126 ms
55,792 KB
testcase_04 AC 125 ms
55,884 KB
testcase_05 AC 128 ms
56,020 KB
testcase_06 AC 125 ms
56,040 KB
testcase_07 AC 642 ms
63,176 KB
testcase_08 AC 620 ms
62,684 KB
testcase_09 AC 517 ms
60,480 KB
testcase_10 AC 527 ms
60,960 KB
testcase_11 AC 541 ms
60,452 KB
testcase_12 AC 528 ms
60,268 KB
testcase_13 AC 646 ms
62,436 KB
testcase_14 AC 581 ms
61,800 KB
testcase_15 AC 614 ms
60,980 KB
testcase_16 AC 613 ms
61,252 KB
testcase_17 AC 126 ms
55,784 KB
testcase_18 AC 126 ms
57,472 KB
testcase_19 AC 122 ms
55,728 KB
testcase_20 AC 125 ms
55,480 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 m = sc.nextLong();
    long A = sc.nextLong();
    long[] a = new long[n - 1];
    for(int i = 0; i < n - 1; i++) {
      a[i] = sc.nextLong();
    }
    Arrays.sort(a);
    long l = 0;
    long r = n - 1;
    long ans = -1;
    while(l < r) {
      long med = (l + r) / 2;
      long t = A + a[(int)med];
      long p = 0;
      int left = 0;
      int right = n - 2;
      while(left < right) {
        if(left == (int)med) {
          left++;
        } else if(right == (int)med) {
          right--;
        } else {
          long s = a[left] + a[right];
          if(s > t) {
            p++;
            right--;
            left++;
          } else {
            left++;
          }
        }
      }
      if(p >= m) {
        l = med + 1;
      } else {
        ans = a[(int)med];
        r = med;
      }
    }
    System.out.println(ans);
  }
}
0