Submission #782035

# Submission time Handle Problem Language Result Execution time Memory
782035 2023-07-13T14:56:31 Z TeaTime Cipele (COCI18_cipele) C++17
90 / 90
693 ms 8388 KB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

ll n, m;
vector<ll> vec1, vec2;

const ll INF = 1'000'000'100;

bool check(int val) {
    multiset<ll> st;
    for (auto c : vec2) st.insert(c);
    sort(vec1.begin(), vec1.end());

    for (auto c : vec1) {
        while (true) {
            if (st.empty()) return 0;

            ll v = (*st.begin());
            st.erase(st.begin());

            if (abs(c - v) > val) continue;
            break;
        }
    }

    return 1;
}

int main() {
    fastInp;

    cin >> n >> m;
    vec1.resize(n);
    vec2.resize(m);

    for (auto &c : vec1) cin >> c;
    for (auto &c : vec2) cin >> c;

    if (n > m) {
        swap(n, m);
        swap(vec1, vec2);
    }

    int l = -1, r = INF;
    while (r - l > 1) {
        ll mid = (ll(l) + r) / 2;

        if (check(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }

    cout << r;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 479 ms 8128 KB Output is correct
2 Correct 656 ms 8388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 667 ms 8276 KB Output is correct
2 Correct 685 ms 8380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 464 KB Output is correct
2 Correct 18 ms 732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 624 KB Output is correct
2 Correct 20 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 668 KB Output is correct
2 Correct 22 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 596 KB Output is correct
2 Correct 19 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 684 KB Output is correct
2 Correct 17 ms 732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 693 ms 7600 KB Output is correct
2 Correct 391 ms 5036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 617 ms 7680 KB Output is correct
2 Correct 349 ms 6704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 538 ms 7260 KB Output is correct
2 Correct 510 ms 7180 KB Output is correct