結果
| 問題 |
No.1597 Matrix Sort
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-09 23:06:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 450 ms / 1,500 ms |
| コード長 | 1,319 bytes |
| コンパイル時間 | 3,305 ms |
| コンパイル使用メモリ | 198,148 KB |
| 最終ジャッジ日時 | 2025-01-22 22:32:43 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
string sep = " ";
if(v.size()) os << v[0];
for(int i=1; i<v.size(); i++) os << sep << v[i];
return os;
}
template<typename T>
istream& operator>>(istream &is, vector<T> &v){
for(int i=0; i<v.size(); i++) is >> v[i];
return is;
}
#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif
int main() {
ios_base::sync_with_stdio(false);
cout << setprecision(20) << fixed;
int n;
ll k, p;
cin >> n >> k >> p;
vector<ll> a(n), b(n);
cin >> a >> b;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
ll lb=-1, ub=p;
while(ub-lb>1){
ll x = (ub+lb)/2;
ll m = 0;
for(int i=0; i<n; i++){
m += lower_bound(a.begin(), a.end(), x-b[i]+1) - a.begin();
m += lower_bound(a.begin(), a.end(), p+x-b[i]+1) - lower_bound(a.begin(), a.end(), p-b[i]);
}
if(m<k) {
lb = x;
} else {
ub = x;
}
}
cout << ub << endl;
return 0;
}