130712025-01-05 15:15:44PallanekPéterA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 33/508ms524 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    vector<array<int,3>> vonatok(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> vonatok[i][0] >> vonatok[i][1];
        vonatok[i][2]=i+1;
    }

    sort(vonatok.begin(), vonatok.end());

    int j = 1, mx = 0, ats = 0;
    vector<int> utvonal;
    int i = 0;

    while (j <= m) {
        bool talalt = false;
        int legjobb_vonat = -1;

        while (i < n && get<0>(vonatok[i]) <= j) {
            if (get<1>(vonatok[i]) > mx) {
                mx = get<1>(vonatok[i]);
                legjobb_vonat = get<2>(vonatok[i]);
                talalt = true;
            }
            i++;
        }

        if (!talalt) {
            cout << -1 << endl;
            return 0;
        }

        utvonal.push_back(legjobb_vonat);
        j = mx + 1;
    }
    
    cout << utvonal.size()-1 << endl;
    for (int i : utvonal) {
        cout << i << " ";
    }
}
SubtaskSumTestVerdictTimeMemory
base33/50
1Accepted0/01ms320 KiB
2Wrong answer0/08ms508 KiB
3Accepted1/11ms320 KiB
4Accepted1/11ms336 KiB
5Accepted2/21ms320 KiB
6Wrong answer0/21ms320 KiB
7Accepted2/21ms344 KiB
8Accepted2/22ms320 KiB
9Accepted2/22ms320 KiB
10Accepted2/23ms508 KiB
11Wrong answer0/23ms320 KiB
12Partially correct1/24ms320 KiB
13Partially correct1/21ms320 KiB
14Partially correct1/22ms428 KiB
15Accepted2/23ms320 KiB
16Partially correct1/24ms348 KiB
17Partially correct1/26ms320 KiB
18Wrong answer0/26ms496 KiB
19Wrong answer0/27ms500 KiB
20Partially correct1/27ms512 KiB
21Partially correct1/28ms520 KiB
22Wrong answer0/27ms320 KiB
23Accepted2/27ms516 KiB
24Accepted2/27ms520 KiB
25Accepted2/27ms520 KiB
26Accepted2/27ms524 KiB
27Accepted2/27ms404 KiB
28Accepted2/27ms520 KiB