結果
問題 |
No.507 ゲーム大会(チーム決め)
|
ユーザー |
![]() |
提出日時 | 2020-01-31 08:34:54 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 212 ms / 3,000 ms |
コード長 | 1,723 bytes |
コンパイル時間 | 1,800 ms |
コンパイル使用メモリ | 78,144 KB |
実行使用メモリ | 56,412 KB |
最終ジャッジ日時 | 2024-09-17 06:45:15 |
合計ジャッジ時間 | 4,981 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
import java.util.*; import java.io.*; public class Main { static int[] dp; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int n = Integer.parseInt(first[0]); int mm = Integer.parseInt(first[1]); int mine = Integer.parseInt(br.readLine()); int[] points = new int[n - 1]; for (int i = 0; i < n - 1; i++) { points[i] = Integer.parseInt(br.readLine()); } Arrays.sort(points); int left = 0; int right = n - 2; if (check(right, mine + points[right], points) >= mm) { System.out.println(-1); return; } if (check(left, mine + points[left], points) < mm) { System.out.println(points[left]); return; } while (right - left > 1) { int m = (left + right) / 2; if (check(m, mine + points[m], points) >= mm) { left = m; } else { right = m; } } System.out.println(points[right]); } static int check(int target, int score, int[] arr) { int left = 0; int right = arr.length - 1; int count = 0; while (left < right) { if (left == target) { left++; } else if(right == target) { right--; } else if (arr[left] + arr[right] <= score) { left++; } else { count++; left++; right--; } } return count; } }