結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー 37zigen37zigen
提出日時 2017-04-22 08:03:49
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,454 bytes
コンパイル時間 2,666 ms
コンパイル使用メモリ 75,836 KB
実行使用メモリ 62,652 KB
最終ジャッジ日時 2023-09-28 12:58:25
合計ジャッジ時間 11,203 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,824 KB
testcase_01 AC 126 ms
55,860 KB
testcase_02 AC 127 ms
55,612 KB
testcase_03 AC 128 ms
55,992 KB
testcase_04 AC 127 ms
55,792 KB
testcase_05 AC 128 ms
55,844 KB
testcase_06 AC 128 ms
55,956 KB
testcase_07 AC 649 ms
62,528 KB
testcase_08 AC 677 ms
62,652 KB
testcase_09 AC 559 ms
60,348 KB
testcase_10 AC 552 ms
60,580 KB
testcase_11 AC 565 ms
60,972 KB
testcase_12 AC 556 ms
60,656 KB
testcase_13 AC 695 ms
62,532 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	long INF = (long) (1e19);
	PrintWriter pw = new PrintWriter(System.out);

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long a0 = -1;
		long[] a = new long[n - 1];
		a0 = sc.nextLong();
		for (int i = 0; i < n - 1; ++i) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		solve(a0, a, n, m);
	}

	void solve(long a0, long[] a, int n, int m) {
		int left = -1;// leftとペアを結んだとき商品は得られない場合が存在する。
		int right = a.length;// rightとペアを結んだとき確実に商品が得られる。
		while (right - left > 1) {
			int middle = (right + left) / 2;

			long sum = a0 + a[middle];
			int s = 0;
			int cnt = 0;
			for (int i = a.length - 1; i >= 0 && s < i; --i) {
				while (s + 1 < i && a[i] + a[s] <= sum) {
					++s;
				}
				if (a[i] + a[s] > sum) {
					++cnt;
					++s;
				}
				if (cnt == m)
					break;
			}
			if (cnt == m) {
				left = middle;
			} else {
				right = middle;
			}

		}
		if (right != a.length) {
			System.out.println(a[right]);
		} else {
			System.out.println(-1);
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0