Submission #98956

# Submission time Handle Problem Language Result Execution time Memory
98956 2019-02-27T18:28:42 Z SecretAgent007 Cipele (COCI18_cipele) C++17
90 / 90
72 ms 3284 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define INF 1e18

vector<int> a;
vector<int> b;

bool check(int x){
    int p = 1;
    for(int i = 1; i < a.size(); i++){
        while(p < b.size() && abs(b[p]-a[i]) > x){
            p++;
        }
        if(p >= b.size()) return false;
        p++;
    }
    return true;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    a.resize(n+1);
    b.resize(m+1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= m; i++){
        cin >> b[i];
    }
    sort(a.begin()+1, a.end());
    sort(b.begin()+1, b.end());
    if(n > m){
        swap(a,b);
        swap(n,m);
    }
    int l = 0; int r = INF;
    while(l < r){
        int mid = (l+r)>>1;
        if(check(mid)){
            r = mid;
        }else{
            l = mid+1;
        }
    }
    cout << l << endl;
}

Compilation message

cipele.cpp: In function 'bool check(long long int)':
cipele.cpp:12:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1; i < a.size(); i++){
                    ~~^~~~~~~~~~
cipele.cpp:13:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(p < b.size() && abs(b[p]-a[i]) > x){
               ~~^~~~~~~~~~
cipele.cpp:16:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(p >= b.size()) return false;
            ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 40 ms 1920 KB Output is correct
2 Correct 72 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 2044 KB Output is correct
2 Correct 51 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 5 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 444 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 1664 KB Output is correct
2 Correct 34 ms 2356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 1816 KB Output is correct
2 Correct 31 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 1656 KB Output is correct
2 Correct 44 ms 3284 KB Output is correct