답안 #894460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894460 2023-12-28T10:07:53 Z vjudge1 Cipele (COCI18_cipele) C++17
90 / 90
31 ms 3788 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define russian setlocale(LC_ALL,"Russian_Russia.20866");
#define file freopen("condense2.in", "r", stdin), freopen("condense2.out", "w", stdout);
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pli pair<ll, int>
#define all(s) s.begin(), s.end()
#define pb push_back
#define ins insert
#define mp make_pair
#define sz(x) x.size()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mem(x) memset(x, 0, sizeof(x))

const ll N = 100010;
const ll M = 1e9 + 7;
const ll block = 316;
const ll mod = 1e9 + 7;
const ll P = 263;
const ld pi = acos(-1);
const ll inf = 1e18;

ll add(ll a, ll b) {
    if(a + b < 0) return a + b + mod;
    if(a + b >= mod) return a + b - mod;
    return a + b;
}

ll sub(ll a, ll b) {
    return (a - b + mod) % mod;
}

ll mul(ll a, ll b) {
    return a * b % mod;
}

ll binpow(ll a, ll n) {
    ll res = 1;
    while(n) {
        if(n & 1) res = mul(res, a);
        a = mul(a, a);
        n >>= 1;
    }
    return res;
}

ll inv(ll x) {
    return binpow(x, mod - 2);
}
ll n, m;
vector<ll> mn, mx;
//n <= m
//sz(mn) <= sz(mx)
bool check(ll x) {
    ll idx = 0;
    for(auto to: mx) {
        if(abs(to - mn[idx]) > x) continue;
        idx++;
        if(idx == n) break;
    }
    return (idx == n);
}
void solve() {
    cin >> n >> m;
    for(ll i = 1, l; i <= n; i++) {
        cin >> l;
        mn.pb(l);
    }
    for(ll i = 1, r; i <= m; i++) {
        cin >> r;
        mx.pb(r);
    }
    if(n > m) {
        swap(n, m);
        swap(mn, mx);
    }
    sort(all(mn));
    sort(all(mx));
    ll l = -1, r = 1e9;
    while(r > l + 1) {
        ll mid = (l + r) / 2;
        if(check(mid)) r = mid;
        else l = mid;
    }
    cout << r << '\n';
}
signed main() {
    speed;
    //file;
    int test = 1;
    //cin >> test;
    while(test--) {
        solve();
    }
}
/*
3 4
1 1 1
5 5 5 5
 */
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 2776 KB Output is correct
2 Correct 30 ms 2972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 2780 KB Output is correct
2 Correct 31 ms 2620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 564 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 2400 KB Output is correct
2 Correct 19 ms 2268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 2516 KB Output is correct
2 Correct 14 ms 2776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 2516 KB Output is correct
2 Correct 27 ms 3788 KB Output is correct