結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー takeya_okinotakeya_okino
提出日時 2019-08-11 16:16:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 996 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 74,188 KB
実行使用メモリ 66,652 KB
最終ジャッジ日時 2023-10-11 21:16:18
合計ジャッジ時間 10,887 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,788 KB
testcase_01 AC 126 ms
55,924 KB
testcase_02 AC 125 ms
56,516 KB
testcase_03 WA -
testcase_04 AC 125 ms
55,596 KB
testcase_05 AC 125 ms
55,804 KB
testcase_06 AC 126 ms
55,944 KB
testcase_07 AC 637 ms
62,788 KB
testcase_08 WA -
testcase_09 AC 524 ms
60,236 KB
testcase_10 AC 536 ms
60,420 KB
testcase_11 AC 545 ms
60,928 KB
testcase_12 AC 526 ms
60,624 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 123 ms
56,128 KB
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

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--;
          } else {
            left++;
          }
        }
      }
      if(p >= m) {
        l = med + 1;
      } else {
        ans = a[(int)med];
        r = med;
      }
    }
    System.out.println(ans);
  }
}
0