73392024-01-07 21:13:51szabelrA lehető legkevesebb átszállás (50 pont)cpp17Partially correct 46/509ms5040 KiB
#include <iostream>
#include <algorithm>

using namespace std;

struct VonatInfo {
    int sorszam;
    int start;
    int stop;
};

bool kisebbVonat(VonatInfo v1, VonatInfo v2) {
    return v1.start < v2.start;
}

int main() {

    VonatInfo A[10000];
    int hasznaltVonat[10000];
    int N, M;
    cin >> N >> M;

    for (int i = 0; i < N; i++) {
        int start, stop;
        cin >> start >> stop;
        A[i].sorszam = i + 1;
        A[i].start = start;
        A[i].stop = stop;
    }

    //sort(A, A+N, kisebbVonat);

    int hol = 1, maxAllomas = 1;
    int K = 0;
    int i = 0;
    int maxHasznaltVonat;

    bool eljut = true;

    while (eljut && hol < M) {
        maxAllomas = hol;
        while (A[i].start <= hol) {
            if (A[i].stop > maxAllomas) {
                maxAllomas = A[i].stop;
                maxHasznaltVonat = A[i].sorszam;
            }
            i++;
        }
        if (hol != maxAllomas) {
            hol = maxAllomas;
            hasznaltVonat[K++] = maxHasznaltVonat;
        }
        else {
            eljut = false;
        }
    }

    if (eljut) {
        cout << K-1 << endl;

        //sort(hasznaltVonat, hasznaltVonat+K);
        for (int i = 0; i < K; i++) cout << hasznaltVonat[i] << " ";
    }
    else {
        cout << "-1";
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base46/50
1Accepted0/03ms2436 KiB
2Accepted0/08ms2556 KiB
3Accepted1/13ms2696 KiB
4Accepted1/13ms2824 KiB
5Accepted2/23ms2984 KiB
6Accepted2/23ms3076 KiB
7Accepted2/23ms3204 KiB
8Accepted2/23ms3204 KiB
9Accepted2/24ms3340 KiB
10Accepted2/24ms3408 KiB
11Accepted2/24ms3408 KiB
12Accepted2/26ms3556 KiB
13Accepted2/23ms3628 KiB
14Accepted2/24ms3704 KiB
15Accepted2/24ms3784 KiB
16Accepted2/26ms4076 KiB
17Accepted2/27ms3952 KiB
18Accepted2/28ms3840 KiB
19Accepted2/28ms4208 KiB
20Accepted2/28ms4164 KiB
21Accepted2/28ms4288 KiB
22Accepted2/29ms4696 KiB
23Partially correct1/28ms4560 KiB
24Partially correct1/28ms4652 KiB
25Accepted2/28ms4868 KiB
26Partially correct1/28ms4952 KiB
27Partially correct1/28ms5040 KiB
28Accepted2/28ms4952 KiB