이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
///Binary Search The Answer
int n,m;
int A[100005];
int B[100005];
bool possible(int maxDiff) ///Returns whether is possible to match shoes with at most maxDiff ugliness
{
int j=0;
for(int i=0;i<n;i++){
while(j<m && abs(A[i]-B[j]) > maxDiff)
j++;
if(j==m)
return false; //We have no more shoes to match
j++;
}
return true; //Shoes matched successfully
}
int binarySearch() ///Return the first moment when is possible
{
int k=-1;
for(int b=1000000007;b>=1;b/=2){
while(!possible(k+b)) k+=b;
}
return k+1;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>A[i];
}
for(int i=0;i<m;i++){
cin>>B[i];
}
sort(A,A+n);
sort(B,B+m);
cout<<binarySearch()<<'\n';
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |