44012023-03-27 15:40:52kdbA lehető legkevesebb átszállás (50 pont)cpp17Accepted 50/504ms5080 KiB
#include <iostream>
#include <vector>
using namespace std;

struct Train
{
    int start;
    int end;
};

ostream& operator<<(ostream& os, const vector<int>& input)
{
    for (const int i : input) os << i << " ";
    return os;
}

int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<Train>vec(n + 1);

    for (size_t i = 1; i < n + 1; i++)
    {
        int a, b;
        cin >> a >> b;
        vec[i] = { a, b };
    }
    vector<int>ans;
    int i = 1, covered = 1;
    while (covered < m)
    {
        int best = -1;
        while (i <= n and vec[i].start <= covered)
        {
            if (best == -1 or vec[best].end < vec[i].end) best = i;
            i++;

        }
        if (best == -1)
        {
            cout << -1 << "\n";
            return 0;
        }
        else
        {
            covered = vec[best].end;
            ans.push_back(best);
        }
    }
    cout << ans.size() - 1 << "\n" << ans << "\n";
}
/*
6 9
1 2
1 4
2 6
3 4
6 9
7 9


*/
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/04ms2268 KiB
3Accepted1/13ms2264 KiB
4Accepted1/12ms2348 KiB
5Accepted2/23ms2484 KiB
6Accepted2/23ms2696 KiB
7Accepted2/23ms2920 KiB
8Accepted2/23ms3092 KiB
9Accepted2/23ms3440 KiB
10Accepted2/23ms3404 KiB
11Accepted2/23ms3672 KiB
12Accepted2/24ms3632 KiB
13Accepted2/23ms3872 KiB
14Accepted2/23ms4140 KiB
15Accepted2/23ms4128 KiB
16Accepted2/24ms4456 KiB
17Accepted2/24ms4592 KiB
18Accepted2/24ms4648 KiB
19Accepted2/24ms4840 KiB
20Accepted2/24ms4812 KiB
21Accepted2/24ms4816 KiB
22Accepted2/24ms4808 KiB
23Accepted2/24ms4808 KiB
24Accepted2/24ms4804 KiB
25Accepted2/24ms4808 KiB
26Accepted2/24ms4948 KiB
27Accepted2/24ms4948 KiB
28Accepted2/24ms5080 KiB