답안 #472264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
472264 2021-09-13T10:40:54 Z SaraMostafa Cipele (COCI18_cipele) C++14
36 / 90
1000 ms 2332 KB
#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define endl "\n"
#define Sara ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const long long mod=998244353;
const double PI=acos(-1);
int main()
{
    //freopen("input.in","r",stdin);
    Sara
// 2nd st
    int n,m;
    cin>>n>>m;
    vector<ll>a(n),b(m);
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<m; i++)
        cin>>b[i];
           
    int id=0;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
     if(n==m){
        ll mx=0;
for(int i=0;i<n;i++){
    mx=max(mx,abs(a[i]-b[i]));
}
cout<<mx<<endl;
return 0;
    }
    if(n<m)
    {
        ll mn1=1e9;
        for(int i=0; i<=(m-1)-(n-1); i++)
        {
            ll mx=0;
            int k=0;
            for(int j=i; j<i+n; j++)
            {
                mx=max(mx,abs(b[j]-a[k]));
               // cout<<b[j]<<' '<<a[k]<<endl;
                k++;
            }
            //cout<<mx<<endl;
            mn1=min(mn1,mx);
        }
        //
        vector<bool>vs(m);
        vector<ll>bn(n);
        for(int i=n-1; i>=0; i--)
        {
            ll mn=1e9;
            for(int j=0; j<m; j++)
            {
                if(vs[j])
                    continue;
                if(abs(a[i]-b[j])<mn)
                {
                    mn=abs(a[i]-b[j]);
                    id=j;
                }
            }
            vs[id]=1;
            bn[i]=b[id];
        }
        ll mx=0;
        for(int i=0; i<n; i++)
        {
            mx=max(mx,abs(a[i]-bn[i]));
        }
        cout<<min(mx,mn1)<<endl;
        return 0;
    }
        ll mn1=1e9;
        for(int i=0; i<=(n-1)-(m-1); i++)
        {
            ll mx=0;
            int k=0;
            for(int j=i; j<i+m; j++)
            {
                mx=max(mx,abs(a[j]-b[k]));
                k++;
            }
            mn1=min(mn1,mx);
        }
        //
    vector<bool>vs(n);
    vector<ll>an(m);
    for(int i=m-1; i>=0; i--)
    {
        ll mn=1e9;
        for(int j=0; j<n; j++)
        {
            if(vs[j])
                continue;
            if(abs(b[i]-a[j])<mn)
            {
                mn=abs(b[i]-a[j]);
                id=j;
            }
        }
        vs[id]=1;
        an[i]=a[id];
    }
    ll mx=0;
    for(int i=0; i<m; i++)
    {
        mx=max(mx,abs(b[i]-an[i]));
    }
    cout<<min(mx,mn1)<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 1896 KB Output is correct
2 Correct 41 ms 1988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 1896 KB Output is correct
2 Correct 42 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 372 KB Output is correct
2 Correct 34 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 332 KB Output is correct
2 Correct 34 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 60 ms 388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 56 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1082 ms 1484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1083 ms 2332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1082 ms 1484 KB Time limit exceeded
2 Halted 0 ms 0 KB -