Submission #472398

# Submission time Handle Problem Language Result Execution time Memory
472398 2021-09-13T12:57:15 Z BidoTeima Cipele (COCI18_cipele) C++17
90 / 90
682 ms 10112 KB
/// isA AC
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void ACPLS(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
#define tc int tttttt;cin>>tttttt;while(tttttt--)
#define sumrange(l,r,arr) (l==0?arr[r]:arr[r]-arr[l-1])
bool isint(const string& s){
    bool ok=1;
    for(char i:s)
        ok&=isdigit(i);
    return ok;
}
bool isseq(const string& s){
    return !isint(s);
}
int main(){
    ACPLS();
    int n,m;
    cin>>n>>m;
    vector<int>a;
    if(n<=m){
    a.resize(n);
    for(auto&i:a)cin>>i;
    multiset<int>b;
    for(int i = 0; i < m; i++){
        ll x;
        cin>>x;
        b.insert(x);
    }
    int lo=0,hi=1e9,ans=hi;
    sort(a.begin(), a.end());
    while(lo<=hi){
        ll mid=(lo+hi)/2;
        multiset<int>ms=b;
        bool ok = 1;
        for(int i = 0; i < n; i++){
            if(ms.empty())break;
            auto it = ms.lower_bound(a[i]-mid);
            if(it==ms.end()||abs((*it)-a[i])>mid){
                ok=0;
                break;
            }
            ms.erase(it);
        }
        if(ok){
            ans=mid;
            hi=mid-1;
        }else lo=mid+1;
        }
    cout<<ans;
    }
    else{
    a.resize(m);
    multiset<int>b;
    for(int i = 0; i < n; i++){
        ll x;
        cin>>x;
        b.insert(x);
    }
    for(auto&i:a)cin>>i;
    int lo=0,hi=1e9,ans=hi;
    sort(a.begin(), a.end());
    while(lo<=hi){
        ll mid=(lo+hi)/2;
        multiset<int>ms=b;
        bool ok = 1;
        for(int i = 0; i < m; i++){
            if(ms.empty())break;
            auto it = ms.lower_bound(a[i]-mid);
            if(it==ms.end()||abs((*it)-a[i])>mid){
                ok=0;
                break;
            }
            ms.erase(it);
        }
        if(ok){
            ans=mid;
            hi=mid-1;
        }else lo=mid+1;
    }
    cout<<ans;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 301 ms 10052 KB Output is correct
2 Correct 443 ms 10112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 417 ms 10048 KB Output is correct
2 Correct 417 ms 10004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 460 KB Output is correct
2 Correct 14 ms 800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 776 KB Output is correct
2 Correct 14 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 716 KB Output is correct
2 Correct 14 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 716 KB Output is correct
2 Correct 18 ms 800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 716 KB Output is correct
2 Correct 15 ms 804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 682 ms 9540 KB Output is correct
2 Correct 243 ms 6040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 455 ms 9348 KB Output is correct
2 Correct 224 ms 8740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 477 ms 9028 KB Output is correct
2 Correct 354 ms 8636 KB Output is correct