Submission #999680

# Submission time Handle Problem Language Result Execution time Memory
999680 2024-06-16T04:46:05 Z vjudge1 Cipele (COCI18_cipele) C++17
90 / 90
83 ms 3748 KB
#include "bits/stdc++.h"
using namespace std;
    
long long n, m;
const long long MXN = 100005;
    
long long a1[MXN], a2[MXN];
    
bool works(long long x) {
    long long lpt = 0;
    long long rpt = 0;
    for (long long i=0; i<n; i++) {
        long long at = a1[i];
        long long mxr = at + x;
        long long mnr = at - x;
        while (rpt < m && a2[rpt] <= mxr) {
            rpt++;
        }
        while (lpt < m && a2[lpt] < mnr) {
            lpt++;
        }
        if (lpt == rpt) {
            return false;
        }
        lpt++;
    }
    return true;
}
    
int main() {
    
    cin >> n >> m;
    
    if (n < m) {
        for (long long i=0; i<n; i++) {
            cin >> a1[i];
        }
        for (long long i=0; i<m; i++) {
            cin >> a2[i];
        }
    }
    else {
        for (long long i=0; i<n; i++) {
            cin >> a2[i];
        }
        for (long long i=0; i<m; i++) {
            cin >> a1[i];
        }
        swap(n, m);
    }
    
    sort(a1, a1+n); sort(a2, a2+m);
    
    long long low = 0;
    long long high = INT_MAX;
    
    while (low + 1 < high) {
        long long mid = (low + high) / 2;
        bool res = works(mid);
        if (res) {
            high = mid;
        }
        else {
            low = mid;
        }
    }
    
    if (works(low)) {
        cout << low << endl;
    }
    else {
        cout << high << endl;
    }
    
    
    
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 3456 KB Output is correct
2 Correct 80 ms 3748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 3668 KB Output is correct
2 Correct 83 ms 3672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 6 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 564 KB Output is correct
2 Correct 4 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 3 ms 572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 3 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 3160 KB Output is correct
2 Correct 47 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 3408 KB Output is correct
2 Correct 36 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 3080 KB Output is correct
2 Correct 66 ms 3152 KB Output is correct