Submission #745649

# Submission time Handle Problem Language Result Execution time Memory
745649 2023-05-20T18:13:34 Z MilosMilutinovic Cipele (COCI18_cipele) C++14
90 / 90
42 ms 2876 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, a[N], b[N];
bool check(int x) {
    int ptr = 1;
    for (int i = 1; i <= n; i++) {
        while (ptr <= m && a[i] - x > b[ptr]) ptr++;
        if (ptr == m + 1 || a[i] + x < b[ptr]) return false;
        ptr++;
    }
    return true;
}
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
    sort(a + 1, a + n + 1);
    sort(b + 1, b + m + 1);
    if (n > m) {
        swap(n, m);
        for (int i = 1; i < N; i++) swap(a[i], b[i]);
    }
    int low = 0, high = 1e9, ans = 0;
    while (low <= high) {
        int mid = low + high >> 1;
        if (check(mid)) ans = mid, high = mid - 1;
        else low = mid + 1;
    }
    printf("%d", ans);
    return 0;
}

Compilation message

cipele.cpp: In function 'int main()':
cipele.cpp:26:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   26 |         int mid = low + high >> 1;
      |                   ~~~~^~~~~~
cipele.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
cipele.cpp:16:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
      |                                  ~~~~~^~~~~~~~~~~~~
cipele.cpp:17:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
      |                                  ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 27 ms 2580 KB Output is correct
2 Correct 42 ms 2864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 2876 KB Output is correct
2 Correct 40 ms 2804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 320 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 2376 KB Output is correct
2 Correct 29 ms 2020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 2584 KB Output is correct
2 Correct 20 ms 2080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2324 KB Output is correct
2 Correct 34 ms 2544 KB Output is correct