Submission #305098

# Submission time Handle Problem Language Result Execution time Memory
305098 2020-09-22T15:08:28 Z phathnv Cipele (COCI18_cipele) C++11
90 / 90
67 ms 3064 KB
#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

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 time Memory Grader output
1 Correct 35 ms 2688 KB Output is correct
2 Correct 59 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 3064 KB Output is correct
2 Correct 64 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 2424 KB Output is correct
2 Correct 34 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 2556 KB Output is correct
2 Correct 26 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2304 KB Output is correct
2 Correct 51 ms 2640 KB Output is correct