Submission #464701

# Submission time Handle Problem Language Result Execution time Memory
464701 2021-08-13T18:06:51 Z soba Cipele (COCI18_cipele) C++14
90 / 90
121 ms 2648 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 10000+1;

int n ,m , x;
int dp[5001][5001];
vector<int>v1 , v2;
int solve(int i , int rem)
{
    if(rem==0)
        return 0;
    if(i==n)
        return 1e9;
    int &ret=dp[i][rem];
    if(ret!=-1)
        return ret;
    ret=min( max(solve(i+1, rem-1), abs(v1[i]-v2[m-rem]) ) , solve(i+1 , rem) );
    return ret;
}
int main() {

    cin>>n>>m;
    for(int i = 0 ; i < n; i++)
    {
        cin>>x;
        if(n>=m)
            v1.push_back(x);
        else v2.push_back(x);
    }
    for(int i=0 ; i < m ;i++ )
    {
        cin >> x;
        if(n>=m)
        {
            v2.push_back(x);
        }
        else v1.push_back(x);
    }
    if(n<m)swap(n,m);
    int ans=0;
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    if(n==m)
    {
        for(int i = 0;  i< n ;i++)
        {
            ans=max(ans , abs(v1[i]-v2[i]));
        }
        cout << ans;
        return 0;
    }
    int l = 0 , r = 1e9+10  , mid;
    ans=1e9;
    while(l<=r)
    {
        mid=(l+r)>>1;
        int j =0;
        for(int i = 0 ; i < n ; i++)
        {
            if(abs(v1[i]-v2[j])<=mid)
                j++;
            if(j==m)break;
        }
        if(j==m)
        {
            ans=min(ans , mid);
            r=mid-1;
        }
        else l=mid+1;
    }
    cout << ans ;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 82 ms 1704 KB Output is correct
2 Correct 104 ms 1708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 1672 KB Output is correct
2 Correct 103 ms 1652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 8 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 332 KB Output is correct
2 Correct 7 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 7 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 7 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 332 KB Output is correct
2 Correct 6 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 1464 KB Output is correct
2 Correct 68 ms 1860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 1592 KB Output is correct
2 Correct 71 ms 2448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 1572 KB Output is correct
2 Correct 102 ms 2648 KB Output is correct