Submission #305098

#TimeUsernameProblemLanguageResultExecution timeMemory
305098phathnvCipele (COCI18_cipele)C++11
90 / 90
67 ms3064 KiB
#include <bits/stdc++.h>

#define mp make_pair
#define X first
#define Y second
#define taskname "Cipele"

using namespace std;

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

const int N = 1e5 + 1;

int m, n, l[N], r[N];

void readInput(){
    scanf("%d %d", &m, &n);
    for(int i = 1; i <= m; i++)
        scanf("%d", &l[i]);
    for(int i = 1; i <= n; i++)
        scanf("%d", &r[i]);
}

bool check(int x){
    int ptr = 1;
    for(int i = 1; i <= m; i++){
        while (abs(l[i] - r[ptr]) > x && ptr <= n)
            ptr++;
        if (ptr == n + 1)
            return 0;
        ptr++;
    }
    return 1;
}

void solve(){
    if (m > n){
        swap(m, n);
        swap(l, r);
    }
    sort(l + 1, l + 1 + m);
    sort(r + 1, r + 1 + n);

    int lo = 0, hi = 1e9, res = -1;
    while (lo <= hi){
        int mid = (lo + hi) >> 1;
        if (check(mid)){
            res = mid;
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }
    assert(res > -1);
    printf("%d", res);
}

int main(){
    //freopen(taskname".inp", "r", stdin);
    //freopen(taskname".out", "w", stdout);
    readInput();
    solve();
    return 0;
}

Compilation message (stderr)

cipele.cpp: In function 'void readInput()':
cipele.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |     scanf("%d %d", &m, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~
cipele.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |         scanf("%d", &l[i]);
      |         ~~~~~^~~~~~~~~~~~~
cipele.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |         scanf("%d", &r[i]);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...