72862024-01-06 10:10:14szabelrA lehető legkevesebb átszállás (50 pont)cpp17Time limit exceeded 13/50300ms4540 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/03ms2164 KiB
2Time limit exceeded0/0300ms1532 KiB
3Runtime error0/18ms3368 KiB
4Accepted1/13ms2544 KiB
5Accepted2/23ms2740 KiB
6Accepted2/23ms2868 KiB
7Wrong answer0/23ms2964 KiB
8Wrong answer0/24ms3056 KiB
9Wrong answer0/24ms3188 KiB
10Wrong answer0/24ms3364 KiB
11Time limit exceeded0/2300ms3708 KiB
12Time limit exceeded0/2259ms2820 KiB
13Time limit exceeded0/2273ms3140 KiB
14Time limit exceeded0/2270ms3760 KiB
15Time limit exceeded0/2261ms4028 KiB
16Wrong answer0/216ms4156 KiB
17Time limit exceeded0/2300ms3180 KiB
18Time limit exceeded0/2266ms4280 KiB
19Time limit exceeded0/2248ms3600 KiB
20Time limit exceeded0/2273ms3716 KiB
21Time limit exceeded0/2266ms3856 KiB
22Time limit exceeded0/2263ms4516 KiB
23Accepted2/248ms4536 KiB
24Accepted2/217ms4540 KiB
25Time limit exceeded0/2300ms3540 KiB
26Accepted2/223ms4480 KiB
27Accepted2/259ms4492 KiB
28Wrong answer0/2120ms4472 KiB