結果
問題 | No.507 ゲーム大会(チーム決め) |
ユーザー | Kmcode1 |
提出日時 | 2017-04-21 22:42:54 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 351 ms / 3,000 ms |
コード長 | 1,071 bytes |
コンパイル時間 | 1,373 ms |
コンパイル使用メモリ | 152,424 KB |
実行使用メモリ | 8,688 KB |
最終ジャッジ日時 | 2023-09-27 11:26:41 |
合計ジャッジ時間 | 5,252 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 0 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 270 ms
8,684 KB |
testcase_08 | AC | 278 ms
8,572 KB |
testcase_09 | AC | 266 ms
8,544 KB |
testcase_10 | AC | 275 ms
8,652 KB |
testcase_11 | AC | 287 ms
8,688 KB |
testcase_12 | AC | 264 ms
8,540 KB |
testcase_13 | AC | 327 ms
8,572 KB |
testcase_14 | AC | 335 ms
8,584 KB |
testcase_15 | AC | 351 ms
8,588 KB |
testcase_16 | AC | 333 ms
8,572 KB |
testcase_17 | AC | 1 ms
4,380 KB |
testcase_18 | AC | 2 ms
4,376 KB |
testcase_19 | AC | 1 ms
4,380 KB |
testcase_20 | AC | 2 ms
4,380 KB |
ソースコード
#include<bits/stdc++.h> #include<unordered_set> #include<unordered_map> using namespace std; #define MAX 100002 int n; int m; vector<int> v; vector<int> vv; multiset<int> s; bool ok(int val){ s.clear(); for (int i = 0; i < vv.size(); i++){ s.insert(vv[i]); } auto it = s.lower_bound(val); s.erase(it); int rankk = 0; while (!s.empty()){ auto f = *s.rbegin(); s.erase(s.lower_bound(f)); int need = val + v[0] - f; need++; auto it = s.lower_bound(need); if (it != s.end()){ s.erase(it); rankk++; } else{ break; } } rankk++; return rankk <= m; } int main(){ cin >> n >> m; for (int i = 0; i < n; i++){ int a; scanf("%d", &a); v.push_back(a); if (i)vv.push_back(a); } sort(vv.begin(), vv.end()); int mint = 0; int maxt = vv.size() - 1; while (mint + 1 < maxt){ int mid = (mint + maxt) >> 1; if (ok(vv[mid])){ maxt = mid; } else{ mint = mid; } } if (ok(vv[mint])){ cout << vv[mint] << endl; } else{ if (ok(vv[maxt])){ cout << vv[maxt] << endl; } else{ puts("-1"); } } return 0; }