40822023-03-13 08:56:49tamasmarkA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 4/508ms4072 KiB
// legkevesebb 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;
};
vector<adat>x;
vector<int >megold;
int i, j, n, m, maxi,a,b;

int main()
{
    cin >> m >> n;
    x.resize(m + 1);
    for (i = 1; i <= m; ++i)
    {
        cin >> x[i].kezd >> x[i].veg;
    }
    for (i=1;i<=m;++i)
    {
        if (x[i].kezd == 1)
        {
            if (x[i].veg > maxi)
            {
                maxi = x[i].veg;
                a = i;
            }
        }
    }
    megold.push_back(a);
    i = a;
    while (i <= m && x[i].veg < n)
    {
        j = i;
        maxi = 0;
        while (j <= m && x[j].kezd <= x[i].veg)
        {
            if (x[j].veg >= x[maxi].veg)
            {
                maxi = j;
            }
            j++;
        }
        if (maxi == 0)
        {
            cout << -1;
            return 0;
        }
        else
        {
            megold.push_back(maxi);
            i = maxi;
        }
        ++i;
    }
    cout << megold.size()-1 << "\n";
    for (auto& e : megold) cout << e << " ";
    return 0;
}
/*
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
base4/50
1Wrong answer0/03ms1748 KiB
2Wrong answer0/08ms2216 KiB
3Wrong answer0/12ms1996 KiB
4Wrong answer0/12ms2128 KiB
5Accepted2/23ms2340 KiB
6Wrong answer0/23ms2552 KiB
7Wrong answer0/23ms2812 KiB
8Wrong answer0/23ms3032 KiB
9Wrong answer0/24ms3240 KiB
10Wrong answer0/24ms3208 KiB
11Wrong answer0/24ms3220 KiB
12Wrong answer0/26ms3236 KiB
13Wrong answer0/23ms3316 KiB
14Wrong answer0/24ms3312 KiB
15Wrong answer0/24ms3296 KiB
16Wrong answer0/26ms3320 KiB
17Wrong answer0/27ms3368 KiB
18Wrong answer0/28ms3636 KiB
19Wrong answer0/28ms3684 KiB
20Wrong answer0/28ms3828 KiB
21Wrong answer0/28ms3892 KiB
22Wrong answer0/28ms3920 KiB
23Wrong answer0/28ms3776 KiB
24Wrong answer0/28ms3604 KiB
25Wrong answer0/28ms4008 KiB
26Wrong answer0/28ms4072 KiB
27Accepted2/28ms4072 KiB
28Wrong answer0/28ms3964 KiB