40642023-03-13 07:25:23bzsofiaA lehető legkevesebb átszállás (50 pont)cpp11Runtime error 48/5063ms64848 KiB
// Atszallas.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>

using namespace std;

struct adat
{
    int kezd, veg;
};

long long i, n, m, maxi, j;
vector <long long> v;

int main()
{
    cin >> n>>m;
    vector <adat> x(n + 1);

    for (i = 1; i <= n; ++i)
    {
        cin >> x[i].kezd >> x[i].veg;
    }

    i = 1;
    maxi = 0;
    while (i<=n && x[i].kezd == 1)
    {
        if (x[i].veg >= x[maxi].veg) maxi = i;
        ++i;
    }

    v.push_back(maxi);
    i = maxi;

    while (i<=n && x[i].veg < m)
    {
        j = i;
        maxi = 0;
        while (j<=n && x[j].kezd <= x[i].veg)
        {
            if (x[j].veg >= x[maxi].veg)
            {
                maxi = j;
            }
            ++j;
        }

        if (maxi == 0)
        {
            cout << "-1";
            return 0;
        }
        else
        {
             i = maxi;
             v.push_back(maxi);
        }
    }

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

    return 0;
}

// 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
base48/50
1Accepted0/03ms1812 KiB
2Accepted0/08ms2260 KiB
3Runtime error0/157ms64848 KiB
4Runtime error0/163ms64608 KiB
5Accepted2/23ms2472 KiB
6Accepted2/23ms2704 KiB
7Accepted2/23ms2908 KiB
8Accepted2/23ms3016 KiB
9Accepted2/24ms3020 KiB
10Accepted2/24ms3004 KiB
11Accepted2/24ms3012 KiB
12Accepted2/26ms3280 KiB
13Accepted2/23ms3204 KiB
14Accepted2/24ms3340 KiB
15Accepted2/24ms3436 KiB
16Accepted2/26ms3704 KiB
17Accepted2/27ms3940 KiB
18Accepted2/28ms3896 KiB
19Accepted2/28ms4212 KiB
20Accepted2/28ms4116 KiB
21Accepted2/28ms4380 KiB
22Accepted2/28ms4340 KiB
23Accepted2/28ms4332 KiB
24Accepted2/28ms4372 KiB
25Accepted2/28ms4332 KiB
26Accepted2/28ms4368 KiB
27Accepted2/28ms4492 KiB
28Accepted2/28ms4464 KiB