Submission #668732

# Submission time Handle Problem Language Result Execution time Memory
668732 2022-12-04T19:02:57 Z Mystic03 Cipele (COCI18_cipele) C++17
90 / 90
48 ms 2908 KB
#include <bits/stdc++.h>

using namespace std;

// Binary search for answer. An answer works if you greedily chose elements to
// be paired and that works. If an answer works, then all above will work too.

const int MAXNM = 1e5 + 3;

int n, m, l[MAXNM], r[MAXNM];


bool ok(int val) {
    int pt = 1;

    for (int i = 1; i <= n; i++) {
        if (abs(r[pt] - l[i]) <= val) pt++;
        if (pt == m + 1) return true;
    }

    return pt == m + 1;
}


int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    cin >> n >> m;

    if (n >= m) {
        for (int i = 0; i < n; i++) cin >> l[i];
        for (int i = 0; i < m; i++) cin >> r[i];
    }
    else {
        for (int i = 0; i < n; i++) cin >> r[i];
        for (int i = 0; i < m; i++) cin >> l[i];
        swap(n, m);
    }

    sort(l, l + n);
    sort(r, r + m);

    int lp = 0, rp = 1e9;

    while (lp < rp) {
        int mid = (lp + rp) >> 1;
        if (ok(mid)) rp = mid;
        else lp = mid + 1;
    }

    cout << lp << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2644 KB Output is correct
2 Correct 47 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2908 KB Output is correct
2 Correct 47 ms 2892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 2380 KB Output is correct
2 Correct 28 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2488 KB Output is correct
2 Correct 28 ms 1900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2244 KB Output is correct
2 Correct 39 ms 2436 KB Output is correct