結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー tentententen
提出日時 2023-06-14 09:57:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 269 ms / 3,000 ms
コード長 2,638 bytes
コンパイル時間 2,536 ms
コンパイル使用メモリ 86,836 KB
実行使用メモリ 58,860 KB
最終ジャッジ日時 2023-09-04 23:22:46
合計ジャッジ時間 7,245 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,564 KB
testcase_01 AC 43 ms
49,620 KB
testcase_02 AC 42 ms
49,536 KB
testcase_03 AC 44 ms
49,732 KB
testcase_04 AC 43 ms
49,924 KB
testcase_05 AC 42 ms
49,460 KB
testcase_06 AC 43 ms
49,692 KB
testcase_07 AC 269 ms
58,604 KB
testcase_08 AC 265 ms
58,860 KB
testcase_09 AC 216 ms
57,056 KB
testcase_10 AC 204 ms
58,600 KB
testcase_11 AC 208 ms
57,748 KB
testcase_12 AC 216 ms
55,952 KB
testcase_13 AC 261 ms
58,452 KB
testcase_14 AC 247 ms
58,016 KB
testcase_15 AC 242 ms
57,752 KB
testcase_16 AC 239 ms
57,916 KB
testcase_17 AC 44 ms
50,008 KB
testcase_18 AC 45 ms
49,636 KB
testcase_19 AC 42 ms
49,512 KB
testcase_20 AC 44 ms
49,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int target = sc.nextInt();
        int[] values = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {
            values[i] = sc.nextInt();
        }
        Arrays.sort(values);
        int left = -1;
        int right = n - 1;
        while (right - left > 1) {
            int x = (left + right) / 2;
            int up = n - 2;
            int down = 0;
            int count = 0;
            while (down < up && count < m) {
                if (up == x) {
                    up--;
                    continue;
                }
                if (down == x) {
                    down++;
                    continue;
                }
                if (values[up] + values[down] > target + values[x]) {
                    count++;
                    up--;
                    down++;
                } else {
                    down++;
                }
            }
            if (count >= m) {
                left = x;
            } else {
                right = x;
            }
        }
        if (right == n - 1) {
            System.out.println(-1);
        } else {
            System.out.println(values[right]);
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0