124852024-12-19 08:43:24feheristvanA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 6/508ms520 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct vonat{
    int veg, kezd, ind;
};

int main(){
    vector <vonat> trains;
    vector <int> selected_trains;
    int n, m;
    cin >> n >> m;
    trains.resize(n);
    for(int i = 0 ; i < n; i ++){
        cin >> trains[i].kezd >> trains[i].veg;
        trains[i].ind = i;
    }
    int current_end = 0, farthest = 0, indx = 0;
    while(current_end < m){
        current_end = trains[indx].veg;
        while(indx < n and trains[indx].kezd <= current_end){
            farthest = max(trains[indx].veg, farthest);
            indx ++;
        }
        if(farthest < current_end){
            cout << "-1";
            return 0;
        }
        current_end = farthest;
        selected_trains.push_back(trains[indx - 1].ind);
    }
    cout << selected_trains.size() - 1 << endl;
    for(auto i : selected_trains)
        cout << i << " ";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/01ms320 KiB
2Wrong answer0/08ms320 KiB
3Accepted1/11ms320 KiB
4Wrong answer0/11ms320 KiB
5Accepted2/21ms320 KiB
6Wrong answer0/21ms320 KiB
7Wrong answer0/21ms412 KiB
8Wrong answer0/22ms516 KiB
9Wrong answer0/22ms508 KiB
10Wrong answer0/23ms320 KiB
11Wrong answer0/23ms320 KiB
12Wrong answer0/24ms368 KiB
13Wrong answer0/22ms320 KiB
14Wrong answer0/22ms424 KiB
15Wrong answer0/23ms380 KiB
16Wrong answer0/24ms320 KiB
17Wrong answer0/24ms320 KiB
18Wrong answer0/26ms496 KiB
19Wrong answer0/26ms500 KiB
20Wrong answer0/27ms320 KiB
21Wrong answer0/27ms320 KiB
22Wrong answer0/27ms520 KiB
23Partially correct1/27ms520 KiB
24Partially correct1/27ms520 KiB
25Wrong answer0/27ms396 KiB
26Partially correct1/27ms320 KiB
27Wrong answer0/27ms520 KiB
28Wrong answer0/27ms516 KiB