Submission #464673

# Submission time Handle Problem Language Result Execution time Memory
464673 2021-08-13T16:29:01 Z ahmedfouadnew Cipele (COCI18_cipele) C++17
90 / 90
377 ms 2368 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int mod=1e9+7;
int a[100001],b[100001];
int n,m;

bool ok(int x)
{
    int cur=-1;
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        int l=lower_bound(b,b+m,a[i]-x)-b;
        int r=upper_bound(b,b+m,a[i]+x)-b-1;
        if(max(cur+1,l)<=r)
        {
            cur=max(cur+1,l);
            cnt++;
        }
    }
    return (cnt>=m);
}
int bs()
{
    int s=0,e=1e10;
    while(s<e)
    {
        int mid=s+(e-s)/2;
        if(ok(mid))
        {
            e=mid;
        }
        else
        {
            s=mid+1;
        }
    }
    return s;
}
signed main()
{
    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)
    {
        for(int i=0;i<m;i++)
        {
            swap(a[i],b[i]);
        }
        swap(n,m);
    }
    sort(a,a+n);
    sort(b,b+m);
    cout<<bs()<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 377 ms 2228 KB Output is correct
2 Correct 360 ms 2368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 372 ms 2348 KB Output is correct
2 Correct 373 ms 2348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 332 KB Output is correct
2 Correct 10 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 412 KB Output is correct
2 Correct 10 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 428 KB Output is correct
2 Correct 10 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 332 KB Output is correct
2 Correct 10 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 436 KB Output is correct
2 Correct 11 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 354 ms 2208 KB Output is correct
2 Correct 229 ms 1560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 350 ms 2200 KB Output is correct
2 Correct 272 ms 1732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 330 ms 2160 KB Output is correct
2 Correct 319 ms 1988 KB Output is correct