結果
問題 |
No.507 ゲーム大会(チーム決め)
|
ユーザー |
![]() |
提出日時 | 2020-07-16 00:55:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,187 bytes |
コンパイル時間 | 1,117 ms |
コンパイル使用メモリ | 91,840 KB |
実行使用メモリ | 8,296 KB |
最終ジャッジ日時 | 2024-11-22 19:22:43 |
合計ジャッジ時間 | 5,765 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 RE * 1 |
ソースコード
#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(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; }