結果
問題 | No.507 ゲーム大会(チーム決め) |
ユーザー |
![]() |
提出日時 | 2019-10-24 19:58:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 49 ms / 3,000 ms |
コード長 | 1,777 bytes |
コンパイル時間 | 869 ms |
コンパイル使用メモリ | 108,804 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-18 03:03:55 |
合計ジャッジ時間 | 2,208 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
#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 << ":" << val << endl; while (right - left > 1) { while (right > 0 && used[right]) right--; while (left < right && (used[left] || a[right] + a[left] <= val)) left++; if (left < right && !used[left] && !used[right] && a[left] + a[right] > val) { cnt++; used[right] = true; used[left] = true; // cerr << "!" << a[left] << "+" << a[right] << endl; } } // cerr << cnt << endl; if (cnt >= m) { ng = mid; } else { ok = mid; } } if (0 <= ok && ok < n - 1) { cout << a[ok] << endl; } else { cout << -1 << endl; } return 0; }