40972023-03-14 12:38:53bzsofiaA lehető legkevesebb átszállás (50 pont)cpp11Runtime error 47/5063ms64632 KiB
#include <iostream>
#include <vector>

using namespace std;

long long n, m, i, j, a, b, maxi;

int main()
{
    cin >> m >> n;
    vector <long long> x(n + 1);
    vector <long long> honnan(n + 1);
    vector <long long> v;

    for (i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        if (x[a] <= b)
        {
            x[a] = b;
            honnan[a] = i;
        }
    }

    i = 1;
    while (x[i] < n)
    {
        v.push_back(honnan[i]);
        maxi = i;

        for (j = i + 1; j <= x[i]; ++j)
        {
            if (x[j] > x[maxi])
            {
                maxi = j;
            }
        }

        /*if (x[maxi] <= x[i])
        {
            cout << "-1";
            return 0;
        }*/

        i = maxi;
    }

    v.push_back(honnan[maxi]);

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

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base47/50
1Accepted0/03ms1812 KiB
2Accepted0/010ms5044 KiB
3Runtime error0/163ms64632 KiB
4Runtime error0/146ms64396 KiB
5Partially correct1/23ms2688 KiB
6Accepted2/23ms2776 KiB
7Accepted2/23ms2868 KiB
8Accepted2/23ms2864 KiB
9Accepted2/24ms3172 KiB
10Accepted2/24ms3620 KiB
11Accepted2/26ms4432 KiB
12Accepted2/26ms4564 KiB
13Accepted2/24ms3960 KiB
14Accepted2/24ms4832 KiB
15Accepted2/24ms4940 KiB
16Accepted2/26ms4940 KiB
17Accepted2/28ms5976 KiB
18Accepted2/28ms6056 KiB
19Accepted2/28ms6376 KiB
20Accepted2/29ms6768 KiB
21Accepted2/29ms7120 KiB
22Accepted2/29ms6924 KiB
23Accepted2/29ms6136 KiB
24Accepted2/29ms6744 KiB
25Accepted2/29ms7272 KiB
26Accepted2/29ms7612 KiB
27Accepted2/29ms7692 KiB
28Accepted2/29ms7704 KiB