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