95852024-02-23 12:44:09AblablablaSzínes szobák (50 pont)cpp17Accepted 50/5086ms6152 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

int n, k, m;
vector<int> szobak;
vector<pii> kerdesek;

int jo(int akt){
    for(pii x : kerdesek){
        if(szobak[akt] == x.first){
            akt += x.second;
        }

        if(akt == -1){
            return -1;
        } else if(akt == n){
            return 1;
        }
    }
    return 0;
}

int main()
{
    cin >> n >> k >> m;

    szobak.assign(n, 0);
    for(int i = 0; i < n; i++){
        cin >> szobak[i];
    }

    kerdesek.assign(m, {0, 0});
    for(pii &x : kerdesek){
        cin >> x.first >> x.second;
    }

    int balH = -1;
    int l = 0, r = n - 1;
    while(l <= r){
        int mid = (l + r) / 2;

        if(jo(mid) == -1){
            balH = mid;
            l = mid + 1;
        } else{
            r = mid - 1;
        }
    }

    int jobbH = n;
    l = 0;
    r = n - 1;
    while(l <= r){
        int mid = (l + r) / 2;

        if(jo(mid) == 1){
            jobbH = mid;
            r = mid - 1;
        } else{
            l = mid + 1;
        }
    }

    cout << (balH + 1) + (n - jobbH) << "\n";
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1880 KiB
2Accepted0/086ms4516 KiB
3Accepted1/13ms2348 KiB
4Accepted1/13ms2404 KiB
5Accepted1/13ms2608 KiB
6Accepted1/13ms2836 KiB
7Accepted1/13ms2912 KiB
8Accepted1/13ms3044 KiB
9Accepted1/13ms3272 KiB
10Accepted1/14ms3496 KiB
11Accepted1/13ms3560 KiB
12Accepted1/14ms3552 KiB
13Accepted1/18ms3876 KiB
14Accepted1/14ms3840 KiB
15Accepted1/16ms3784 KiB
16Accepted1/18ms3904 KiB
17Accepted1/18ms4048 KiB
18Accepted1/18ms3984 KiB
19Accepted1/150ms5080 KiB
20Accepted1/182ms5996 KiB
21Accepted1/161ms5084 KiB
22Accepted1/167ms5476 KiB
23Accepted1/178ms5820 KiB
24Accepted1/182ms6000 KiB
25Accepted1/182ms6000 KiB
26Accepted1/182ms6148 KiB
27Accepted3/375ms6000 KiB
28Accepted3/375ms6068 KiB
29Accepted3/375ms6152 KiB
30Accepted3/375ms6068 KiB
31Accepted3/375ms5996 KiB
32Accepted3/375ms6000 KiB
33Accepted4/439ms4568 KiB
34Accepted4/464ms5480 KiB