Submission #240656

# Submission time Handle Problem Language Result Execution time Memory
240656 2020-06-20T13:08:51 Z DavidDamian Cipele (COCI18_cipele) C++11
90 / 90
53 ms 1272 KB
#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];
    }
    if(n>m){
        swap(n,m);
        swap(A,B);
    }
    sort(A,A+n);
    sort(B,B+m);
    cout<<binarySearch()<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 35 ms 1144 KB Output is correct
2 Correct 53 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 1144 KB Output is correct
2 Correct 52 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 1016 KB Output is correct
2 Correct 32 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 1024 KB Output is correct
2 Correct 28 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 1088 KB Output is correct
2 Correct 44 ms 1152 KB Output is correct