Submission #106635

# Submission time Handle Problem Language Result Execution time Memory
106635 2019-04-19T10:47:19 Z stefdasca Cipele (COCI18_cipele) C++14
90 / 90
97 ms 2944 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define mod 1000000007
#define fi first
#define se second
using namespace std;
int n, m;
int arr[100002], arr2[100002];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // shuffle(permutation.begin(), permutation.end(), rng);
    cin>>n>>m;
    for(int i = 1; i <= n; ++i)
        cin >> arr[i];
    for(int i = 1; i <= m; ++i)
        cin >> arr2[i];
    sort(arr + 1, arr + n + 1);
    sort(arr2 + 1, arr2 + m + 1);
    if(n == m)
    {
        int sol = 0;
        for(int i = 1; i <= n; ++i)
            sol = max(sol, abs(arr[i] - arr2[i]));
        cout << sol << '\n';
    }
    else
    {
        int b = 0;
        int e = 1000000000;
        int sol = -1;
        while(b <= e)
        {
            int mid = (b+e)/2;
            int mtch = 0;
            if(n < m)
            {
                int pos = 1;
                for(int i = 1; i <= m; ++i)
                    if(abs(arr[pos] - arr2[i]) <= mid && pos <= n)
                        ++pos, ++mtch;
            }
            else
            {
                int pos = 1;
                for(int i = 1; i <= n; ++i)
                    if(abs(arr2[pos] - arr[i]) <= mid && pos <= m)
                        ++pos, ++mtch;
            }
            if(mtch == min(n, m))
                sol = mid, e = mid - 1;
            else
                b = mid + 1;
        }
        cout << sol << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2808 KB Output is correct
2 Correct 53 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 2936 KB Output is correct
2 Correct 49 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 484 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 2464 KB Output is correct
2 Correct 34 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 2680 KB Output is correct
2 Correct 97 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 2424 KB Output is correct
2 Correct 39 ms 2552 KB Output is correct