6931 2023. 12. 20 10:47:09 gkata A lehető legkevesebb átszállás (50 pont) cpp17 Elfogadva 50/50 4ms 5892 KiB
// atszallasok.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<queue>

using namespace std;

vector<pair<int, int>>x;
vector<int>ans;

int n, m, i, atn = 1, lj;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    
    cin >> n >> m;
    x.resize(n + 1);

    for (i = 1; i <= n; ++i)
        cin >> x[i].first >> x[i].second;

    i = 1;

    while (atn < m)
    {
        lj = -1;
        while (i <= n && x[i].first <= atn)
        {
            if (lj == -1 || x[lj].second < x[i].second) lj = i;
            ++i;
        }

        if (lj == -1)
        {
            cout << -1 << "\n";
            return 0;
        }

        else
        {
            atn = x[lj].second;
            ans.push_back(lj);
        }
    }

    cout << ans.size() - 1 << "\n";
    for (auto& e : ans) cout << e << " ";
}

/*
6 9
1 2
1 4
2 6
3 4
6 9
7 9
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Részfeladat Összpont Teszt Verdikt Idő Memória
base 50/50
1 Elfogadva 0/0 3ms 1888 KiB
2 Elfogadva 0/0 4ms 2268 KiB
3 Elfogadva 1/1 3ms 2264 KiB
4 Elfogadva 1/1 3ms 2344 KiB
5 Elfogadva 2/2 3ms 2356 KiB
6 Elfogadva 2/2 3ms 2480 KiB
7 Elfogadva 2/2 3ms 2820 KiB
8 Elfogadva 2/2 3ms 2792 KiB
9 Elfogadva 2/2 3ms 3052 KiB
10 Elfogadva 2/2 4ms 3572 KiB
11 Elfogadva 2/2 4ms 3560 KiB
12 Elfogadva 2/2 4ms 3816 KiB
13 Elfogadva 2/2 3ms 3732 KiB
14 Elfogadva 2/2 3ms 3816 KiB
15 Elfogadva 2/2 3ms 3784 KiB
16 Elfogadva 2/2 4ms 3960 KiB
17 Elfogadva 2/2 4ms 4032 KiB
18 Elfogadva 2/2 4ms 4196 KiB
19 Elfogadva 2/2 4ms 4156 KiB
20 Elfogadva 2/2 4ms 4288 KiB
21 Elfogadva 2/2 4ms 4404 KiB
22 Elfogadva 2/2 4ms 4544 KiB
23 Elfogadva 2/2 4ms 4884 KiB
24 Elfogadva 2/2 4ms 4944 KiB
25 Elfogadva 2/2 4ms 5060 KiB
26 Elfogadva 2/2 4ms 5420 KiB
27 Elfogadva 2/2 4ms 5748 KiB
28 Elfogadva 2/2 4ms 5892 KiB