Submission #855716

# Submission time Handle Problem Language Result Execution time Memory
855716 2023-10-01T17:02:37 Z vjudge1 Cipele (COCI18_cipele) C++17
18 / 90
742 ms 10064 KB
//author: Ahmet Alp Orakci
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int i64

#define ONLINE_JUDGE
void solve() {
    int n, m;
    cin >> n >> m;

    vector <int> a(n +1), b(m +1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    for(int i = 1; i <= m; i++) {
        cin >> b[i];
    }

    if(n > m) {
        swap(a, b);
        swap(n, m);
    }

    multiset <i64> ms(b.begin() +1, b.end());
    ms.emplace(-1E18);
    ms.emplace(1E18);

    sort(a.begin(), a.end());

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        auto it = prev(ms.lower_bound(a[i]));
        auto it2 = next(it);

        cerr << a[i] << " :: " << *it << " " << *it2 << "\n";

        if(a[i] - *it <= *it2 - a[i]) {
            ans = max(ans, a[i] - *it);
            ms.erase(it);
        } else {
            ans = max(ans, *it2 - a[i]);
            ms.erase(it2);
        }
    }

    cout << ans;
    
    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1; //cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 673 ms 10064 KB Output is correct
2 Incorrect 708 ms 9808 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 742 ms 9528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 600 KB Output is correct
2 Correct 35 ms 904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 616 KB Output is correct
2 Correct 38 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 506 ms 8164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 601 ms 8644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 504 ms 7932 KB Output isn't correct
2 Halted 0 ms 0 KB -