72792024-01-05 21:22:04szabelrA lehető legkevesebb átszállás (50 pont)cpp17Time limit exceeded 12/50300ms4860 KiB
#include <iostream>
#include <vector>
using namespace std;
int jok[100001]{ 0 };
int tombkezd[100001]{ 0 };
int tombveg[100001]{ 0 };
int main()
{
    int n, m, kezd, veg, hol = 1, hova = 0, jo, valami=0,max=0,z=1,db=0,t=1,ln=0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) 
    {
        cin >> kezd >> veg;
        tombkezd[i] = kezd;
        tombveg[i] = veg;
        if (veg > ln) {
            ln = veg;
        }
    }
    if (ln < m) {
        cout << "-1";
    }
    while (hol < m) 
    {   
        valami = 0;
        for (int i = 1; i <= n; i++) {
            if (tombkezd[i] == hol and tombveg[i]>hova) {
                valami = 1;
                hova = tombveg[i];
                jo = i;
            }
        }
        hol = hova;
        if (hova == max) {
            valami = 0;
        }
        if (hol > max) { 
            max=hol;
        }
        
        if (valami == 0 or hol<max) {
            hol=max-z;
            hova=max-z;
            z++;
            //cout << hol;
        }
        if (valami == 1) {
            jok[t] = jo;
            t++;
            z = 1;
        }
    }
    cout << t - 2<<endl;
    for (int alma = 1; alma <= t - 1; alma++) {
        cout << jok[alma] << " ";
    }

}
SubtaskSumTestVerdictTimeMemory
base12/50
1Accepted0/03ms1884 KiB
2Time limit exceeded0/0300ms1544 KiB
3Runtime error0/17ms3184 KiB
4Time limit exceeded0/1250ms2484 KiB
5Accepted2/23ms2880 KiB
6Accepted2/23ms3044 KiB
7Wrong answer0/24ms3416 KiB
8Wrong answer0/24ms3588 KiB
9Wrong answer0/24ms3652 KiB
10Wrong answer0/24ms3548 KiB
11Time limit exceeded0/2300ms2696 KiB
12Time limit exceeded0/2261ms3520 KiB
13Time limit exceeded0/2232ms3892 KiB
14Time limit exceeded0/2261ms3708 KiB
15Time limit exceeded0/2270ms3924 KiB
16Wrong answer0/210ms4120 KiB
17Time limit exceeded0/2300ms3520 KiB
18Time limit exceeded0/2264ms4208 KiB
19Time limit exceeded0/2264ms4384 KiB
20Time limit exceeded0/2257ms4688 KiB
21Time limit exceeded0/2270ms4692 KiB
22Time limit exceeded0/2286ms3804 KiB
23Accepted2/228ms4656 KiB
24Accepted2/213ms4820 KiB
25Time limit exceeded0/2300ms3888 KiB
26Accepted2/216ms4756 KiB
27Accepted2/235ms4724 KiB
28Wrong answer0/264ms4860 KiB