40812023-03-13 08:53:42bzsofiaA lehető legkevesebb átszállás (50 pont)cpp11Partially correct 49/5010ms7208 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
base49/50
1Accepted0/03ms1808 KiB
2Accepted0/09ms5048 KiB
3Accepted1/13ms2212 KiB
4Accepted1/13ms2424 KiB
5Partially correct1/23ms2636 KiB
6Accepted2/23ms2728 KiB
7Accepted2/23ms3076 KiB
8Accepted2/23ms3024 KiB
9Accepted2/24ms3208 KiB
10Accepted2/24ms3564 KiB
11Accepted2/26ms4384 KiB
12Accepted2/26ms4496 KiB
13Accepted2/23ms3544 KiB
14Accepted2/24ms4388 KiB
15Accepted2/24ms4636 KiB
16Accepted2/26ms4716 KiB
17Accepted2/28ms5752 KiB
18Accepted2/28ms6008 KiB
19Accepted2/28ms6676 KiB
20Accepted2/29ms6828 KiB
21Accepted2/29ms6912 KiB
22Accepted2/210ms6912 KiB
23Accepted2/29ms5872 KiB
24Accepted2/29ms6568 KiB
25Accepted2/29ms6924 KiB
26Accepted2/29ms6948 KiB
27Accepted2/29ms7208 KiB
28Accepted2/29ms7124 KiB