Submission #1115524

# Submission time Handle Problem Language Result Execution time Memory
1115524 2024-11-20T14:53:39 Z duytuandao21 Cipele (COCI18_cipele) C++17
90 / 90
42 ms 4300 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 2e5 + 7;
const int infll = 1e18 + 7;
typedef pair<int, int> pii;

int n, m;
vector<int> a;
vector<int> b;

bool check(int k) {
    int j = 0;
    int cnt = 0;
    for (auto &x : a) {
        while (j < b.size() && abs(b[j] - x) > k) ++j;
        if (j < b.size() && abs(b[j] - x) <= k) {
            // cout << j << ' ' ;
            ++cnt;
            ++j;
        }
    }
    if (cnt == a.size()) return true;
    return false;
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        a.push_back(x);
    }
    for (int i = 1; i <= m; i++) {
        int x; cin >> x;
        b.push_back(x);
    }
    if (a.size() > b.size()) swap(a, b);
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int l = 0, r = 1e9 + 7;
    int res = -1;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (check(mid)) {
            res = mid;
            r = mid - 1;
        } else l = mid + 1;
    }
    cout << res;
}   

Compilation message

cipele.cpp: In function 'bool check(long long int)':
cipele.cpp:17:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         while (j < b.size() && abs(b[j] - x) > k) ++j;
      |                ~~^~~~~~~~~~
cipele.cpp:18:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         if (j < b.size() && abs(b[j] - x) <= k) {
      |             ~~^~~~~~~~~~
cipele.cpp:24:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     if (cnt == a.size()) return true;
      |         ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2764 KB Output is correct
2 Correct 33 ms 4300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2764 KB Output is correct
2 Correct 42 ms 4292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 2 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2520 KB Output is correct
2 Correct 22 ms 2512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2508 KB Output is correct
2 Correct 16 ms 3024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2508 KB Output is correct
2 Correct 28 ms 4044 KB Output is correct