72872024-01-06 10:12:10szabelrA lehető legkevesebb átszállás (50 pont)cpp17Time limit exceeded 13/50300ms4744 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++;
        }
        if (valami == 1) {
            jok[t] = jo;
            t++;
            z = 1;
        }
        if (hol <= 0) {
            cout << "-1";
            break;
        }
    }
    if (hol > 0) {
        cout << t - 2 << endl;
        for (int alma = 1; alma <= t - 1; alma++) {
            cout << jok[alma] << " ";
        }
    }
    

}
SubtaskSumTestVerdictTimeMemory
base13/50
1Accepted0/03ms1888 KiB
2Time limit exceeded0/0300ms1348 KiB
3Runtime error0/18ms3248 KiB
4Accepted1/13ms2500 KiB
5Accepted2/23ms2592 KiB
6Accepted2/23ms2712 KiB
7Wrong answer0/23ms2932 KiB
8Wrong answer0/24ms3144 KiB
9Wrong answer0/24ms3364 KiB
10Wrong answer0/24ms3340 KiB
11Time limit exceeded0/2298ms3428 KiB
12Time limit exceeded0/2230ms3600 KiB
13Time limit exceeded0/2270ms3580 KiB
14Time limit exceeded0/2256ms3828 KiB
15Time limit exceeded0/2273ms3792 KiB
16Wrong answer0/216ms3856 KiB
17Time limit exceeded0/2216ms3076 KiB
18Time limit exceeded0/2273ms3872 KiB
19Time limit exceeded0/2266ms3836 KiB
20Time limit exceeded0/2282ms2996 KiB
21Time limit exceeded0/2270ms3056 KiB
22Time limit exceeded0/2270ms3184 KiB
23Accepted2/248ms4396 KiB
24Accepted2/217ms4396 KiB
25Time limit exceeded0/2256ms3452 KiB
26Accepted2/223ms4604 KiB
27Accepted2/259ms4744 KiB
28Wrong answer0/2122ms4684 KiB