Submission #227887

# Submission time Handle Problem Language Result Execution time Memory
227887 2020-04-29T06:49:10 Z kartel Cipele (COCI18_cipele) C++14
90 / 90
59 ms 2040 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +100500
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

ll a[N], b[N], n, m, i, j, l, r;

bool gd(ll x)
{
    int i, j = 1, cur = 0;
    for (i = 1; i <= n; i++)
    {
        while (j <= m && abs(a[i] - b[j]) > x) j++;
        if (j > m) return 0;
        j++;
    }
    return 1;
}

int main()
{
    srand(time(0));
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

//    in("sum.in");
//    out("output.txt");

    cin >> n >> m;
    for (i = 1; i <= n; i++)
    {
        if (n <= m) cin >> a[i];
              else cin >> b[i];
    }

    for (i = 1; i <= m; i++)
    {
        if (n <= m) cin >> b[i];
              else cin >> a[i];
    }

    if (n > m) swap(n, m);

    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + m);

    l = 0;
    r = 1e18;

    while (l < r)
    {
        ll md = (l + r) / 2;

        if (gd(md)) r = md;
               else l = md + 1;
    }
    cout << l;
}



// 119 78 175 411

Compilation message

cipele.cpp: In function 'bool gd(ll)':
cipele.cpp:28:19: warning: unused variable 'cur' [-Wunused-variable]
     int i, j = 1, cur = 0;
                   ^~~
# Verdict Execution time Memory Grader output
1 Correct 42 ms 1920 KB Output is correct
2 Correct 56 ms 1964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 1920 KB Output is correct
2 Correct 58 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 1664 KB Output is correct
2 Correct 35 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 1664 KB Output is correct
2 Correct 30 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1536 KB Output is correct
2 Correct 47 ms 1664 KB Output is correct