Submission #46384397


Source Code Expand

// TimaDegt <3 :flag_sk:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n; i++) cin >> y[i];
    int mx = x[n-1] + 1;
    set<pair<int, int> > zac;
    zac.insert({ -mx, y[0] });
    int ans = mx;
    for (int i = 0; i + 1 < n; i++)
    {
        if (y[i] < y[i + 1]) // pribudnu zaciatky
        {
            zac.insert({ x[i] + 1, y[i + 1] - y[i] });
        }
        if (y[i] > y[i + 1])
        {
            int k = y[i] - y[i + 1], r = x[i + 1] - 1;
            while (k)
            {
                pair<int, int> p = *zac.begin();
                zac.erase(p);
                ans = min(ans, r - p.first);
                int x = min(p.second, k);
                k -= x, p.second -= x;
                if (p.second) zac.insert(p);
            }
        }
    }
    cout << (ans == mx ? -1 : ans) << "\n";
    return 0;
}

Submission Info

Submission Time
Task D - Interval Counts
User prvocislo
Language C++ 20 (gcc 12.2)
Score 600
Code Size 1344 Byte
Status AC
Exec Time 55 ms
Memory 14076 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 72
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 02_small_11.txt, 02_small_12.txt, 02_small_13.txt, 02_small_14.txt, 03_rand_1_01.txt, 03_rand_1_02.txt, 03_rand_1_03.txt, 03_rand_1_04.txt, 03_rand_1_05.txt, 03_rand_1_06.txt, 03_rand_1_07.txt, 03_rand_1_08.txt, 03_rand_1_09.txt, 03_rand_1_10.txt, 03_rand_1_11.txt, 03_rand_1_12.txt, 03_rand_1_13.txt, 03_rand_1_14.txt, 03_rand_1_15.txt, 04_rand_2_01.txt, 04_rand_2_02.txt, 04_rand_2_03.txt, 04_rand_2_04.txt, 04_rand_2_05.txt, 04_rand_2_06.txt, 04_rand_2_07.txt, 04_rand_2_08.txt, 04_rand_2_09.txt, 04_rand_2_10.txt, 04_rand_2_11.txt, 04_rand_2_12.txt, 04_rand_2_13.txt, 04_rand_2_14.txt, 04_rand_2_15.txt, 05_rand_3_01.txt, 05_rand_3_02.txt, 05_rand_3_03.txt, 05_rand_3_04.txt, 05_rand_3_05.txt, 05_rand_3_06.txt, 05_rand_3_07.txt, 05_rand_3_08.txt, 05_rand_3_09.txt, 05_rand_3_10.txt, 05_rand_3_11.txt, 05_rand_3_12.txt, 05_rand_3_13.txt, 05_rand_3_14.txt, 05_rand_3_15.txt, 06_infinity_1_01.txt, 06_infinity_1_02.txt, 06_infinity_1_03.txt, 06_infinity_1_04.txt, 06_infinity_1_05.txt, 07_infinity_2_01.txt, 07_infinity_2_02.txt, 07_infinity_2_03.txt, 07_infinity_2_04.txt, 07_infinity_2_05.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 1 ms 3484 KiB
01_sample_02.txt AC 1 ms 3600 KiB
01_sample_03.txt AC 1 ms 3604 KiB
02_small_01.txt AC 1 ms 3416 KiB
02_small_02.txt AC 1 ms 3468 KiB
02_small_03.txt AC 1 ms 3524 KiB
02_small_04.txt AC 1 ms 3460 KiB
02_small_05.txt AC 1 ms 3396 KiB
02_small_06.txt AC 1 ms 3476 KiB
02_small_07.txt AC 1 ms 3472 KiB
02_small_08.txt AC 1 ms 3384 KiB
02_small_09.txt AC 1 ms 3412 KiB
02_small_10.txt AC 1 ms 3460 KiB
02_small_11.txt AC 1 ms 3520 KiB
02_small_12.txt AC 1 ms 3452 KiB
02_small_13.txt AC 1 ms 3420 KiB
02_small_14.txt AC 1 ms 3416 KiB
03_rand_1_01.txt AC 28 ms 4620 KiB
03_rand_1_02.txt AC 29 ms 4656 KiB
03_rand_1_03.txt AC 28 ms 4640 KiB
03_rand_1_04.txt AC 28 ms 4584 KiB
03_rand_1_05.txt AC 29 ms 4572 KiB
03_rand_1_06.txt AC 28 ms 4568 KiB
03_rand_1_07.txt AC 28 ms 4576 KiB
03_rand_1_08.txt AC 28 ms 4616 KiB
03_rand_1_09.txt AC 29 ms 4568 KiB
03_rand_1_10.txt AC 29 ms 4636 KiB
03_rand_1_11.txt AC 29 ms 4496 KiB
03_rand_1_12.txt AC 28 ms 4636 KiB
03_rand_1_13.txt AC 28 ms 4636 KiB
03_rand_1_14.txt AC 28 ms 4604 KiB
03_rand_1_15.txt AC 29 ms 4496 KiB
04_rand_2_01.txt AC 36 ms 10644 KiB
04_rand_2_02.txt AC 37 ms 10672 KiB
04_rand_2_03.txt AC 37 ms 10656 KiB
04_rand_2_04.txt AC 37 ms 10700 KiB
04_rand_2_05.txt AC 37 ms 10708 KiB
04_rand_2_06.txt AC 39 ms 10608 KiB
04_rand_2_07.txt AC 37 ms 10688 KiB
04_rand_2_08.txt AC 37 ms 10672 KiB
04_rand_2_09.txt AC 38 ms 10656 KiB
04_rand_2_10.txt AC 37 ms 10696 KiB
04_rand_2_11.txt AC 37 ms 10724 KiB
04_rand_2_12.txt AC 37 ms 10656 KiB
04_rand_2_13.txt AC 37 ms 10652 KiB
04_rand_2_14.txt AC 37 ms 10652 KiB
04_rand_2_15.txt AC 36 ms 10640 KiB
05_rand_3_01.txt AC 44 ms 11436 KiB
05_rand_3_02.txt AC 35 ms 5400 KiB
05_rand_3_03.txt AC 29 ms 7540 KiB
05_rand_3_04.txt AC 36 ms 5704 KiB
05_rand_3_05.txt AC 28 ms 7520 KiB
05_rand_3_06.txt AC 48 ms 12212 KiB
05_rand_3_07.txt AC 47 ms 11224 KiB
05_rand_3_08.txt AC 44 ms 10968 KiB
05_rand_3_09.txt AC 44 ms 11452 KiB
05_rand_3_10.txt AC 42 ms 10960 KiB
05_rand_3_11.txt AC 44 ms 10396 KiB
05_rand_3_12.txt AC 43 ms 10940 KiB
05_rand_3_13.txt AC 38 ms 8516 KiB
05_rand_3_14.txt AC 36 ms 5428 KiB
05_rand_3_15.txt AC 49 ms 12500 KiB
06_infinity_1_01.txt AC 41 ms 9856 KiB
06_infinity_1_02.txt AC 41 ms 9916 KiB
06_infinity_1_03.txt AC 41 ms 9856 KiB
06_infinity_1_04.txt AC 41 ms 9940 KiB
06_infinity_1_05.txt AC 41 ms 9864 KiB
07_infinity_2_01.txt AC 55 ms 14068 KiB
07_infinity_2_02.txt AC 53 ms 14076 KiB
07_infinity_2_03.txt AC 24 ms 4592 KiB
07_infinity_2_04.txt AC 24 ms 4592 KiB
07_infinity_2_05.txt AC 25 ms 4572 KiB