Submission #646123

# Submission time Handle Problem Language Result Execution time Memory
646123 2022-09-28T18:09:46 Z Hacv16 Cipele (COCI18_cipele) C++17
81 / 90
46 ms 4912 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define sc second
#define fr first
#define all(x) x.begin(), x.end()
#define sz(x) (ll) x.size()
#define dbg(x) cerr << #x << ": [ " << x << " ]\n"

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = 2e6 + 15;
const int INF = 0x3f3f3f3f;

ll n, m;
vector<ll> l, r;

bool f(ll x){
    ll shoes = 0;

    for(int i = 0, j = 0; i < n, j < m; i++, j++){
        while(j < m && abs(r[j] - l[i]) > x) j++;
        if(j != m) shoes++;
    }
    
    return shoes >= n;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;

    for(int i = 0; i < n; i++){
        ll x; cin >> x; l.pb(x);
    }

    for(int i = 0; i < m; i++){
        ll x; cin >> x; r.pb(x);
    }

    if(n > m) swap(l, r), swap(n, m); //always make l the smaller one

    sort(all(l)); sort(all(r));

    ll l = 0, r = INF, ans = INF; 

    while(l <= r){
        ll mid = (l + r) >> 1;
        if(f(mid)) ans = mid, r = mid - 1;
        else l = mid + 1;
    }

    cout << ans << '\n';

    return 0;
}

Compilation message

cipele.cpp: In function 'bool f(ll)':
cipele.cpp:23:29: warning: left operand of comma operator has no effect [-Wunused-value]
   23 |     for(int i = 0, j = 0; i < n, j < m; i++, j++){
      |                           ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 4136 KB Output is correct
2 Correct 39 ms 4220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 4288 KB Output is correct
2 Correct 42 ms 4192 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 384 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 520 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 3728 KB Output is correct
2 Correct 22 ms 2520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 4048 KB Output is correct
2 Runtime error 18 ms 4912 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 3740 KB Output is correct
2 Correct 37 ms 4052 KB Output is correct