Submission #170357

# Submission time Handle Problem Language Result Execution time Memory
170357 2019-12-24T21:37:00 Z mdn2002 Cipele (COCI18_cipele) C++14
72 / 90
63 ms 3000 KB
#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
int n,m,mx,a[100005],b[100005];
bool ck(int x)
{
    if(n>=m)
    {
        int j=0;
        for(int i=0;i<n;i++)
        {
            int aa=max(a[i],b[j]);
            int bb=min(a[i],b[j]);
            if((n-i)<(m-j))return 0;
            if(aa-bb<=x)j++;
            if(j==m)break;
        }
        return 1;
    }
    else
    {
        int j=0;
        for(int i=0;i<m;i++)
        {
            int aa=max(a[j],b[i]);
            int bb=min(a[j],b[i]);
            if((n-j)>(m-i))return 0;
            if(aa-bb<=x)j++;
            if(j==n)break;
        }
        return 1;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("lemonade.in","r",stdin);
    //freopen("lemonade.out","w",stdout);
    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);
    int l=0,r=1e9+1,mid;
    while(l<r)
    {
        mid=(l+r)/2;
        if(ck(mid))r=mid;
        else l=mid+1;
    }
    cout<<l;
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 2680 KB Output is correct
2 Correct 60 ms 3000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 2960 KB Output is correct
2 Correct 63 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Incorrect 5 ms 508 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Incorrect 5 ms 504 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 5 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 2424 KB Output is correct
2 Correct 35 ms 1972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 2680 KB Output is correct
2 Correct 36 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 2424 KB Output is correct
2 Correct 52 ms 2524 KB Output is correct