結果
問題 |
No.507 ゲーム大会(チーム決め)
|
ユーザー |
![]() |
提出日時 | 2019-10-24 19:53:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,633 bytes |
コンパイル時間 | 1,020 ms |
コンパイル使用メモリ | 107,200 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-18 02:59:11 |
合計ジャッジ時間 | 2,369 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 WA * 9 |
ソースコード
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; #define REP(var, a, b) for (int var = (a); var < (b); var++) #define rep(var, n) for (int var = 0; var < (n); ++var) #define ALL(c) (c).begin(), (c).end() #define rALL(c) (c).rbegin(), (c).rend() ll MOD = 1000000007; const ll INF = 1LL << 62; int main() { // ll n, m; cin >> n >> m; ll k; cin >> k; vl a(n - 1); rep(i, n - 1) { cin >> a[i]; } sort(ALL(a)); ll ok = n - 1; ll ng = -1; while (ok - ng > 1) { ll mid = (ok + ng) / 2; ll val = k + a[mid]; vector<bool> used(n - 1, false); used[mid] = true; ll cnt = 0; ll left = 0; ll right = n - 2; // cerr << ng << ":" << ok << ":" << mid << ":" << a[mid] << endl; while (right - left > 1) { while (right > 0 && used[right]) right--; while (left < right && a[right] + a[left] <= val) left++; if (left < right && a[left] + a[right] > val) { cnt++; used[right] = true; used[left] = true; } } if (cnt >= m) { ng = mid; } else { ok = mid; } } if (0 <= ok && ok < n - 1) { cout << a[ok] << endl; } else { cout << -1 << endl; } return 0; }