69312023-12-20 10:47:09gkataA lehető legkevesebb átszállás (50 pont)cpp17Accepted 50/504ms5892 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
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1888 KiB
2Accepted0/04ms2268 KiB
3Accepted1/13ms2264 KiB
4Accepted1/13ms2344 KiB
5Accepted2/23ms2356 KiB
6Accepted2/23ms2480 KiB
7Accepted2/23ms2820 KiB
8Accepted2/23ms2792 KiB
9Accepted2/23ms3052 KiB
10Accepted2/24ms3572 KiB
11Accepted2/24ms3560 KiB
12Accepted2/24ms3816 KiB
13Accepted2/23ms3732 KiB
14Accepted2/23ms3816 KiB
15Accepted2/23ms3784 KiB
16Accepted2/24ms3960 KiB
17Accepted2/24ms4032 KiB
18Accepted2/24ms4196 KiB
19Accepted2/24ms4156 KiB
20Accepted2/24ms4288 KiB
21Accepted2/24ms4404 KiB
22Accepted2/24ms4544 KiB
23Accepted2/24ms4884 KiB
24Accepted2/24ms4944 KiB
25Accepted2/24ms5060 KiB
26Accepted2/24ms5420 KiB
27Accepted2/24ms5748 KiB
28Accepted2/24ms5892 KiB