72852024-01-06 09:05:31MagyarKendeSZLGA lehető legkevesebb átszállás (50 pont)cpp17Accepted 50/504ms4380 KiB
#include <bits/stdc++.h>

#define speed cin.tie(0); ios::sync_with_stdio(0)
#define cinv(v) for (auto& e : v) cin >> e;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define size(v) (int)v.size()
#define has(s, e) s.count(e)

#define max_index(v) max_element(all(v)) - v.begin()
#define min_index(v) min_element(all(v)) - v.begin()
#define smax(x, y) x = max(x, y)
#define smin(x, y) x = min(x, y)

using namespace std;
using ll = long long;
using point = array<int, 2>;

int max(point p) { return max(p[0], p[1]); }
int min(point p) { return min(p[0], p[1]); }

int main() {
    speed;

    int N, M;
    cin >> N >> M;
    
    vector<point> AB(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> AB[i][0] >> AB[i][1];
    }

    vector<int> result;
    int i = 1, pos = 1;

    while (pos < M) {
        int curr = -1;

        while (i <= N && AB[i][0] <= pos) {
            if (curr == -1 || AB[curr][1] < AB[i][1]) {
                curr = i;
            }
            i++; 
        }

        if (curr == -1) {
            cout << -1;
            exit(0);
        }

        pos = AB[curr][1];
        result.push_back(curr);
    }

    cout << size(result) - 1 << '\n';
    for (int x : result) cout << x << ' ';
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2100 KiB
2Accepted0/04ms2544 KiB
3Accepted1/13ms2416 KiB
4Accepted1/13ms2452 KiB
5Accepted2/23ms2648 KiB
6Accepted2/23ms2724 KiB
7Accepted2/23ms2992 KiB
8Accepted2/23ms2884 KiB
9Accepted2/23ms2796 KiB
10Accepted2/23ms3056 KiB
11Accepted2/23ms3144 KiB
12Accepted2/24ms3028 KiB
13Accepted2/23ms3192 KiB
14Accepted2/23ms3548 KiB
15Accepted2/23ms3632 KiB
16Accepted2/24ms3500 KiB
17Accepted2/24ms3768 KiB
18Accepted2/24ms3984 KiB
19Accepted2/24ms4192 KiB
20Accepted2/24ms4284 KiB
21Accepted2/24ms4192 KiB
22Accepted2/24ms4340 KiB
23Accepted2/24ms4268 KiB
24Accepted2/24ms4204 KiB
25Accepted2/24ms4204 KiB
26Accepted2/24ms4380 KiB
27Accepted2/24ms4244 KiB
28Accepted2/24ms4204 KiB