Submission #1115880

# Submission time Handle Problem Language Result Execution time Memory
1115880 2024-11-21T03:13:34 Z ezzzay Cipele (COCI18_cipele) C++14
90 / 90
72 ms 3776 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=3e5+5;
int n,m;
vector<int> a,b;
bool check(int mid){
    int j=0;
    int p=0;
    for(int i=0;i<n;i++){
        if(j==m)return 0;
        while(j<m){
            if(abs(a[i]-b[j])<=mid){
                p++;
                j++;
                break;
            }
            j++;
        }
        
    }
    return p==n;
}
signed main(){
    cin>>n>>m;
    a.resize(n);
    b.resize(m);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<m;i++){
        cin>>b[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(n>m){
        swap(n,m);
        swap(a,b);
    }
    int hi=1e9,lo=0;
    while(hi>=lo){
        int mid=(hi+lo)/2;
        bool u=check(mid);
        if(u){
            hi=mid-1;
        }
        else{
            lo=mid+1;
        }
    }
    cout<<lo;
    
}
/*
4 3
2 39 41 45
39 42 46

*/
# Verdict Execution time Memory Grader output
1 Correct 46 ms 3400 KB Output is correct
2 Correct 66 ms 3656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 3776 KB Output is correct
2 Correct 64 ms 3664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 4 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 5 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 4 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 4 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 4 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 3144 KB Output is correct
2 Correct 39 ms 2128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 3400 KB Output is correct
2 Correct 35 ms 2632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 3060 KB Output is correct
2 Correct 55 ms 3152 KB Output is correct