76832024-01-10 13:00:47adamA lehető legkevesebb átszállás (50 pont)cpp17Runtime error 37/50300ms64424 KiB
#include <bits/stdc++.h>
using namespace std;

pair<int, int> get_longest (pair<int, int> from, vector<pair<int, int>> trains) {
    pair<int, int> highest;
    for (int i = 0; i < trains.size(); i++) {
        if (trains[i].first - 1 <= from.second && trains[i].second <= trains[i].second)
            if (trains[i].second > highest.second)
                highest = pair(i, trains[i].second - 1);
    }
    return highest;

}

int main() {
    cin.tie(nullptr );
    ios_base::sync_with_stdio(false);
    int train_count = 0;
    int station_count = 0;
    cin >> train_count >> station_count;
    vector<pair<int, int>> trains(train_count, pair(0, 0));
    vector<int> stations(station_count, 0);


    for (int i = 0; i < train_count; i++) {
        pair<int, int> train_stops;
        cin >> train_stops.first >> train_stops.second;
        for (int j = 0; j < (train_stops.second - train_stops.first); j++) {
            stations[train_stops.first + j]++;
        }

        trains[i] = train_stops;
    }
    int boardings = -1;
    if (stations[station_count-1] == 0) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> boarded_trains(0, 0);
    pair<int, int> current_station (0, 0);
    while (current_station.second != station_count - 1) {
        boardings++;
        current_station = get_longest(current_station, trains);
        boarded_trains.push_back(current_station.first);

    }
    cout << boardings << endl;
    for (int train : boarded_trains) {
        cout << train + 1 << " ";
    }
    cout << endl;



}
SubtaskSumTestVerdictTimeMemory
base37/50
1Accepted0/03ms1824 KiB
2Accepted0/013ms3224 KiB
3Accepted1/13ms2272 KiB
4Runtime error0/1188ms64424 KiB
5Accepted2/23ms2676 KiB
6Accepted2/23ms2892 KiB
7Accepted2/23ms3040 KiB
8Accepted2/23ms3292 KiB
9Accepted2/23ms3516 KiB
10Accepted2/24ms3640 KiB
11Accepted2/24ms3852 KiB
12Accepted2/26ms3948 KiB
13Accepted2/23ms3816 KiB
14Accepted2/24ms3880 KiB
15Accepted2/24ms4020 KiB
16Accepted2/26ms4056 KiB
17Accepted2/28ms4580 KiB
18Accepted2/210ms4820 KiB
19Accepted2/210ms5060 KiB
20Accepted2/212ms5448 KiB
21Accepted2/213ms5412 KiB
22Accepted2/213ms5496 KiB
23Time limit exceeded0/2300ms4000 KiB
24Time limit exceeded0/2263ms4052 KiB
25Time limit exceeded0/2250ms4268 KiB
26Time limit exceeded0/2273ms4340 KiB
27Time limit exceeded0/2270ms4040 KiB
28Time limit exceeded0/2243ms4044 KiB