Submission #916774

# Submission time Handle Problem Language Result Execution time Memory
916774 2024-01-26T13:51:52 Z sandrofeiqrishvili Cipele (COCI18_cipele) C++14
90 / 90
87 ms 2996 KB
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector <int> a, b;
int check(int mid) {
    int j=0;
    for(int i=0; i<n; i++){
        while(abs(b[j]-a[i])>mid){
            j++;
            if (j == m) return false;
        }
        j++;
        if (j == m && i != n - 1) return false;
    }
    return true;
}
int main(){
    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];
    } 
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if (n > m) {
        swap(n, m);
        swap(a, b);
    }
    int l=0, r=1e9, ans = -1;
    while (l<=r) {
        int mid=(l+r)/2;
        if (check(mid)) {
            ans = mid;
            r = mid - 1;
        } else l = mid + 1;
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 57 ms 1368 KB Output is correct
2 Correct 87 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 1204 KB Output is correct
2 Correct 73 ms 2996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 6 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 4 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 856 KB Output is correct
2 Correct 48 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 1112 KB Output is correct
2 Correct 42 ms 2128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 860 KB Output is correct
2 Correct 62 ms 860 KB Output is correct