40692023-03-13 07:39:43bzsofiaA lehető legkevesebb átszállás (50 pont)cpp11Futási hiba 48/5067ms64848 KiB
// Atszallas.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>

using namespace std;

struct adat
{
    long long 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base48/50
1Elfogadva0/03ms1816 KiB
2Elfogadva0/08ms2364 KiB
3Futási hiba0/167ms64848 KiB
4Futási hiba0/154ms64612 KiB
5Elfogadva2/23ms2468 KiB
6Elfogadva2/23ms2692 KiB
7Elfogadva2/23ms2920 KiB
8Elfogadva2/23ms3156 KiB
9Elfogadva2/24ms3376 KiB
10Elfogadva2/24ms3616 KiB
11Elfogadva2/24ms3844 KiB
12Elfogadva2/26ms3964 KiB
13Elfogadva2/23ms3916 KiB
14Elfogadva2/24ms4004 KiB
15Elfogadva2/24ms3980 KiB
16Elfogadva2/26ms4268 KiB
17Elfogadva2/27ms4596 KiB
18Elfogadva2/28ms4692 KiB
19Elfogadva2/28ms4620 KiB
20Elfogadva2/28ms4540 KiB
21Elfogadva2/28ms4544 KiB
22Elfogadva2/28ms4544 KiB
23Elfogadva2/28ms4544 KiB
24Elfogadva2/28ms4796 KiB
25Elfogadva2/28ms4756 KiB
26Elfogadva2/28ms4756 KiB
27Elfogadva2/28ms4828 KiB
28Elfogadva2/28ms4752 KiB