Submission #819389

# Submission time Handle Problem Language Result Execution time Memory
819389 2023-08-10T10:12:24 Z vjudge1 Cipele (COCI18_cipele) C++17
18 / 90
151 ms 14340 KB
#include<bits/stdc++.h>
#include<math.h>

#define _USE_MATH_DEFINES

using namespace std;

/**struct node
{
    long long idx;
    long long dis;
    node(){}
    node(long long _idx,long long _dis)
    {
        idx=_idx;
        dis=_dis;
    }
    bool operator<(const node &tmp)const{
    return dis>tmp.dis;
    }
};**/

const long long maxn=1e5+10;
const long long mod=1e9+7;

int main()
{
    long long n,m;
    cin>>n>>m;
    vector<long long>L;
    vector<long long>R;
    map<long long,long long>pl;
    map<long long,long long>pr;
    for(long long i=0;i<n;i++)
    {
        long long x;
        cin>>x;
        L.push_back(x);
        pl[L[i]]++;
    }
    for(long long j=0;j<m;j++)
    {
        long long x;
        cin>>x;
        R.push_back(x);
        pr[R[j]]++;
    }
    sort(L.begin(),L.end());
    sort(R.begin(),R.end());
    if(n==m)
    {
        long long mx=0;
        for(long long i=0;i<n;i++)
        {
            mx=max(mx, abs(L[i]-R[i]));
        }
        cout<<mx<<endl;
    }
    else
    {
        if(n>m)
        {
            swap(n,m);
            swap(L,R);
            swap(pl,pr);
        }
        long long ans=0;
        long long j=-1;
        for(long long i=0;i<n;i++)
        {
            long long raz=1e15;
            while(j+1<m-(n-i-1) && abs(L[i]-R[j+1])<=raz)
            {
                raz=abs(L[i]-R[j+1]);
                j++;
                if(raz==0 && pl[L[i]]>1)
                {
                    pl[L[i]]--;
                    break;
                }
            }
            ans=max(ans, raz);
        }
        cout<<ans<<endl;
    }
    return 0;
}


/*5 5
7 6 1 2 10
9 11 6 3 12
*/
# Verdict Execution time Memory Grader output
1 Correct 93 ms 14340 KB Output is correct
2 Correct 151 ms 14332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 14340 KB Output is correct
2 Correct 132 ms 14336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Incorrect 5 ms 980 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Incorrect 5 ms 980 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 101 ms 11564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 122 ms 12744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 114 ms 11328 KB Output isn't correct
2 Halted 0 ms 0 KB -