/* _____ __ __
/^--^\ | () )\ \/ /
\____/ |_()_) |__|
/ \ _____ _ __ __ ____ _ ____ ____ _____
| || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_ _|
\__ __/ |_| |_|/_/\_\|____||____|\____)/__/\__\ |_|
|^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
| | |\ \| | | | | | | | | | | | | | | | | | | | | | | | |
#####/ /#################################################
| | |\/ | | | | | | | | | | | | | | | | | | | | | | | | |
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| |
#include <Orz/i_am_noob.h>
#include <Orz/balbit.h>
#include <Orz/nathanlee726.h>*/
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<ll,ll>;
#define int ll
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair
#define MOD (ll)(1e9+7)
#define INF (1e18)
#define EPS (1e-6)
#ifdef LOCALMEOW
#define debug(...) do{\
cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ <<\
" : ("#__VA_ARGS__ << ") = ";\
_OUT(__VA_ARGS__);\
}while(0)
template<typename T> void _OUT(T x) { cerr << x << "\n"; }
template<typename T,typename...I>
void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); }
#else
#define debug(...)
#endif
void INIT(){ ios::sync_with_stdio(false); cin.tie(0); }
int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
int ans=1,now=b;
while(p){
if(p&1) ans=ans*now%MOD;
p/=2; now=now*now%MOD;
}
return ans;
}
bool check(vector<int> &a,vector<int> &b,int k){
int j=0;
For(i,0,sz(a)-1){
while(j<sz(b) && abs(a[i]-b[j])>k) j++;
if(abs(a[i]-b[j])>k) j++;
if(j>=sz(b)) return false;
j++;
}
return true;
}
int32_t main(){
INIT();
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//I won't misunderstand the problem statement anymore.
//code...
int n,m; cin>>n>>m;
vector<int> a(min(n,m)),b(max(n,m));
if(n>m){
for(auto &i:b) cin>>i;
for(auto &i:a) cin>>i;
}else{
for(auto &i:a) cin>>i;
for(auto &i:b) cin>>i;
}
sort(all(a));
sort(all(b));
int hi=1e9+10,lo=-1;
while(hi-lo>1){
int mi=(hi+lo)/2;
if(check(a,b,mi)) hi=mi;
else lo=mi;
}
cout<<hi<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
1920 KB |
Output is correct |
2 |
Correct |
43 ms |
2040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
1968 KB |
Output is correct |
2 |
Correct |
43 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
1664 KB |
Output is correct |
2 |
Correct |
26 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
1792 KB |
Output is correct |
2 |
Correct |
21 ms |
1536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
1536 KB |
Output is correct |
2 |
Correct |
37 ms |
1664 KB |
Output is correct |