結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー vjudge1
提出日時 2025-02-23 15:14:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 3,000 ms
コード長 872 bytes
コンパイル時間 1,683 ms
コンパイル使用メモリ 162,948 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-02-23 15:14:15
合計ジャッジ時間 3,228 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int N = 1e5 + 10;
int n, k;
int a[N];
inline bool check(int x)
{
    int l = 2, r = n, cnt = 0;
    while (l < r)
    {
        if (l == x)
            l++;
        else if (r == x)
            r--;
        else if (a[l] + a[r] > a[1] + a[x])
            cnt++, l++, r--;
        else
            l++;
    }
    return cnt < k;
}
int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    sort(a + 2, a + 1 + n);
    int l = 2, r = n, ans = -1;
    while (r >= l)
    {
        int mid = (l + r) >> 1;
        if (check(mid))
            ans = mid, r = mid - 1;
        else
            l = mid + 1;
    }
    cout << (ans == -1 ? -1 : a[ans]) << endl;
    return 0;
}
0