73402024-01-07 21:35:32szabelrA lehető legkevesebb átszállás (50 pont)cpp17Partially correct 47/509ms4920 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
base47/50
1Accepted0/03ms2152 KiB
2Accepted0/09ms2352 KiB
3Accepted1/13ms2560 KiB
4Accepted1/13ms2784 KiB
5Accepted2/23ms2992 KiB
6Accepted2/23ms3196 KiB
7Accepted2/23ms3288 KiB
8Accepted2/24ms3652 KiB
9Accepted2/24ms3824 KiB
10Accepted2/24ms3768 KiB
11Accepted2/24ms3956 KiB
12Accepted2/26ms3972 KiB
13Accepted2/23ms4084 KiB
14Accepted2/24ms4296 KiB
15Accepted2/24ms4476 KiB
16Accepted2/26ms4352 KiB
17Accepted2/27ms4352 KiB
18Accepted2/28ms4440 KiB
19Accepted2/28ms4436 KiB
20Accepted2/28ms4528 KiB
21Accepted2/28ms4348 KiB
22Accepted2/28ms4352 KiB
23Accepted2/28ms4348 KiB
24Partially correct1/29ms4484 KiB
25Accepted2/28ms4564 KiB
26Partially correct1/28ms4692 KiB
27Partially correct1/29ms4904 KiB
28Accepted2/28ms4920 KiB