結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー mamekinmamekin
提出日時 2017-04-29 13:57:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 3,000 ms
コード長 1,286 bytes
コンパイル時間 975 ms
コンパイル使用メモリ 106,436 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 20:22:44
合計ジャッジ時間 3,158 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 47 ms
4,348 KB
testcase_08 AC 47 ms
4,348 KB
testcase_09 AC 30 ms
4,352 KB
testcase_10 AC 31 ms
4,348 KB
testcase_11 AC 31 ms
4,352 KB
testcase_12 AC 31 ms
4,352 KB
testcase_13 AC 47 ms
4,352 KB
testcase_14 AC 36 ms
4,348 KB
testcase_15 AC 36 ms
4,348 KB
testcase_16 AC 37 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int solve(const vector<int>& a, int x)
{
    int n = a.size();
    int k = 0;
    int ans = 0;
    for(int i=n-1; i>k; --i){
        while(k < i && a[i] + a[k] <= x)
            ++ k;
        if(k < i)
            ++ ans;
        ++ k;
    }
    return ans;
}

int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(n-1);
    for(int i=0; i<n-1; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());

    int left = 0;
    int right = n - 1;
    while(left < right){
        int mid = (left + right) / 2;
        int y = a[mid];
        a.erase(a.begin() + mid);

        if(solve(a, x + y) < m)
            right = mid;
        else
            left = mid + 1;

        a.insert(a.begin() + mid, y);
    }

    if(left == n - 1)
        cout << -1 << endl;
    else
        cout << a[left] << endl;

    return 0;
}
0