Submission #366263

# Submission time Handle Problem Language Result Execution time Memory
366263 2021-02-13T17:28:31 Z wiwiho Cipele (COCI18_cipele) C++14
90 / 90
53 ms 3072 KB
#include <bits/stdc++.h>

#define eb emplace_back
#define printv(a, b) {\
bool ps = false;\
for(auto pv : a){\
    if(ps) b << ' '; ps = true;\
    b << pv;\
}\
b << "\n";\
}
#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))

using namespace std;

int n, m;
vector<int> a, b;

int check(int k){
    int now = 0;
    int ans = 0;
    for(int i = 0; i < n; i++){
        while(now < m && b[now] < a[i] - k) now++;
        if(now < m && abs(b[now] - a[i]) <= k){
            ans++;
            now++;
        }
    }
    //cerr << "check " << k << " " << ans << "\n";
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    a.resize(n);
    b.resize(m);

    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    lsort(a);
    lsort(b);

    int l = 0, r = 1000000000;
    while(l < r){
        int mid = (l + r) / 2;
        if(check(mid) == min(n, m)) r = mid;
        else l = mid + 1;
    }
    cout << l << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2688 KB Output is correct
2 Correct 46 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 2924 KB Output is correct
2 Correct 53 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 2412 KB Output is correct
2 Correct 27 ms 1772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 2668 KB Output is correct
2 Correct 22 ms 2028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2412 KB Output is correct
2 Correct 39 ms 2668 KB Output is correct