結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー milanis48663220milanis48663220
提出日時 2020-07-16 00:56:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 359 ms / 3,000 ms
コード長 1,257 bytes
コンパイル時間 881 ms
コンパイル使用メモリ 91,124 KB
実行使用メモリ 8,248 KB
最終ジャッジ日時 2023-08-14 19:24:18
合計ジャッジ時間 5,006 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 69 ms
8,104 KB
testcase_08 AC 49 ms
8,248 KB
testcase_09 AC 315 ms
7,992 KB
testcase_10 AC 326 ms
8,016 KB
testcase_11 AC 325 ms
8,156 KB
testcase_12 AC 311 ms
8,208 KB
testcase_13 AC 359 ms
8,100 KB
testcase_14 AC 351 ms
8,144 KB
testcase_15 AC 353 ms
8,144 KB
testcase_16 AC 336 ms
7,992 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N, M;
int a;
vector<int> v;

bool ok(int idx){
    multiset<int> st;
    for(int i = 0; i < N-1; i++){
        if(i == idx) continue;
        st.insert(v[i]);
    }
    int cnt = 0;
    while(true){
        auto p = st.end(); p--;
        int m = *p;
        st.erase(p);
        auto ptr = st.upper_bound(a+v[idx]-m);
        if(ptr == st.end()) break;
        cnt++;
        st.erase(ptr);
        if(st.empty()){
            break;
        }
    }
    return cnt < M; 
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M;
    cin >> a;
    for(int i = 0; i < N-1; i++){
        int b; cin >> b;
        v.push_back(b);
    }
    sort(v.begin(), v.end());
    if(N == 2){
        cout << v[0] << endl;
        return 0;
    }
    if(ok(0)){
        cout << v[0] << endl;
        return 0;
    }
    if(!ok(N-2)){
        cout << -1 << endl;
        return 0;
    }
    int l = 0, r = N-2;
    while(r-l > 1){
        int c = (l+r)/2;
        if(ok(c)) r = c;
        else l = c;
    }
    cout << v[r] << endl;
}
0