44002023-03-27 15:39:38kdbA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 19/504ms4512 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);

    for (size_t i = 0; i < n; 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
base19/50
1Wrong answer0/03ms1700 KiB
2Wrong answer0/04ms2356 KiB
3Accepted1/13ms2208 KiB
4Accepted1/13ms2420 KiB
5Partially correct1/23ms2536 KiB
6Wrong answer0/23ms2680 KiB
7Partially correct1/23ms2780 KiB
8Partially correct1/23ms2824 KiB
9Partially correct1/23ms2952 KiB
10Partially correct1/23ms3180 KiB
11Partially correct1/23ms3512 KiB
12Partially correct1/24ms3732 KiB
13Partially correct1/23ms3756 KiB
14Partially correct1/23ms3980 KiB
15Partially correct1/23ms3984 KiB
16Partially correct1/24ms3900 KiB
17Partially correct1/24ms3916 KiB
18Partially correct1/24ms4332 KiB
19Partially correct1/24ms4504 KiB
20Partially correct1/24ms4444 KiB
21Partially correct1/24ms4476 KiB
22Partially correct1/24ms4492 KiB
23Wrong answer0/24ms4488 KiB
24Wrong answer0/24ms4492 KiB
25Wrong answer0/24ms4512 KiB
26Wrong answer0/24ms4512 KiB
27Wrong answer0/24ms4512 KiB
28Wrong answer0/24ms4512 KiB