結果
問題 | No.1597 Matrix Sort |
ユーザー |
|
提出日時 | 2022-02-13 03:24:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 377 ms / 1,500 ms |
コード長 | 1,699 bytes |
コンパイル時間 | 4,597 ms |
コンパイル使用メモリ | 255,608 KB |
最終ジャッジ日時 | 2025-01-27 22:57:26 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
// #define _GLIBCXX_DEBUG #include<bits/stdc++.h> #include <atcoder/all> #define rep(i, n) for (long long i = 0; i < (n); i++) #define rep1(i, n) for(long long i = 1; i <= (n); i++) #define all(v) v.begin(),v.end() #define decimal(n) cout << fixed << setprecision(n); using namespace std; using namespace atcoder; using ll = long long; using vl = vector<ll>; using P = pair<ll,ll>; using vvl = vector<vl>; using vc = vector<char>; using vvc = vector<vc>; // using mint = modint998244353; using mint = modint1000000007; const ll MOD = 1000000007; const ll MAX = 2000100; const ll inf = 3e18; const long double pi = acos(-1); template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } ll lcm(ll a,ll b){ return (a*b) / gcd(a,b); } ll n,k,p; vl a,b; //ここに適切な判断条件を書く bool isOK(ll index){ ll cnt = 0; rep(i, n){ cnt += upper_bound(all(b), index - a[i]) - b.begin(); cnt += upper_bound(all(b), p + index - a[i]) - lower_bound(all(b), p - a[i]); } if(cnt >= k) return true; return false; } //臨機応変に引数を書き換える ll binary_search() { //どっちがngか,どっちがokか認識しているか? //探索範囲の上限,下限をしっかり理解しているか? ll ng = -1; ll ok = p - 1; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (isOK(mid)) ok = mid; else ng = mid; } return ok; } int main(){ cin >> n >> k >> p; a.resize(n); b.resize(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; sort(all(a)); sort(all(b)); cout << binary_search() << endl; }