Submission #58944575


Source Code Expand

/// Msaa el 5ra
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i, a, b) for (int i = a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair(x, y)
#define popCnt(x) (__builtin_popcountll(x))
//#define int ll

using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;

const int N = 2e5 + 5, A = 26, LG = 19, MOD = (119 << 23) +1, MOD2 = 1e9 + 7;
const long double PI = acos(-1);
const long double EPS = 1e-7;

const ll MAX = 1e15;



void doWork() {
    int n;
    cin >> n;
    vector<int> a(n), b(n-1);

    f(i,0,n)    cin >> a[i];
    f(i,0,n-1)    cin >> b[i];
    sort(all(a));
    sort(all(b));
    int lo = 1, hi = 1000000001;
    while(lo < hi) {
        int md = lo + (hi-lo)/2;
        bool ok = true, taken = false;
        int j = 0;
        f(i,0,n) {
            if(j==n - 1) {
                if(a[i] > md) {
                    ok = false;
                    break;
                }
            }   else {
                if(md <= b[j] && !taken) {
                    taken = true;
                    if(a[i] > md) {
                        ok = false;
                        break;
                    }
                }   else {
                    if(a[i] > b[j]) {
                        ok = false;
                        break;
                    }
                    j += 1;
                }
            }
        }
        if(ok) hi = md;
        else lo = md + 1;
    }

    if(lo == 1000000001)    lo = -1;
    cout << lo << "\n";

}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
//  cin >> t;
  while (t--) {
    doWork();
  }
}

Submission Info

Submission Time
Task C - Prepare Another Box
User triplem5ds
Language C++ 20 (gcc 12.2)
Score 350
Code Size 1854 Byte
Status AC
Exec Time 50 ms
Memory 4724 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 30
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 02_random2_12.txt, 02_random2_13.txt, 02_random2_14.txt, 02_random2_15.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3384 KiB
00_sample_01.txt AC 1 ms 3392 KiB
00_sample_02.txt AC 1 ms 3476 KiB
01_random_00.txt AC 16 ms 3480 KiB
01_random_01.txt AC 17 ms 3432 KiB
01_random_02.txt AC 46 ms 4628 KiB
01_random_03.txt AC 45 ms 4588 KiB
02_random2_00.txt AC 50 ms 4576 KiB
02_random2_01.txt AC 49 ms 4584 KiB
02_random2_02.txt AC 49 ms 4580 KiB
02_random2_03.txt AC 48 ms 4540 KiB
02_random2_04.txt AC 48 ms 4584 KiB
02_random2_05.txt AC 48 ms 4720 KiB
02_random2_06.txt AC 49 ms 4612 KiB
02_random2_07.txt AC 48 ms 4556 KiB
02_random2_08.txt AC 49 ms 4592 KiB
02_random2_09.txt AC 49 ms 4580 KiB
02_random2_10.txt AC 50 ms 4648 KiB
02_random2_11.txt AC 48 ms 4636 KiB
02_random2_12.txt AC 49 ms 4668 KiB
02_random2_13.txt AC 49 ms 4560 KiB
02_random2_14.txt AC 48 ms 4568 KiB
02_random2_15.txt AC 49 ms 4724 KiB
03_random3_00.txt AC 46 ms 4612 KiB
03_random3_01.txt AC 45 ms 4572 KiB
03_random3_02.txt AC 46 ms 4636 KiB
04_handmade_00.txt AC 1 ms 3436 KiB
04_handmade_01.txt AC 1 ms 3420 KiB
04_handmade_02.txt AC 1 ms 3524 KiB
04_handmade_03.txt AC 26 ms 4596 KiB