57102023-09-09 18:35:30TomaSajtA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 49/504ms6576 KiB
#include <bits/stdc++.h>
using namespace std;

struct line {
  int s, e;
};

int main() {
  cin.tie(0), ios::sync_with_stdio(0);

  int n, m;
  cin >> n >> m;

  vector<line> lines(n);
  for (auto& [s, e] : lines) cin >> s >> e;

  int pos = 1, i = 0;
  vector<int> sol;
  while (pos < m && i < n) {
    int bestI = -1;
    while (i < n && lines[i].s <= pos) {
      if (bestI == -1 || lines[i].e > lines[bestI].e) bestI = i;
      i++;
    }
    if (bestI == -1) {
      cout << "-1";
      return 0;
    }
    pos = lines[bestI].e;
    sol.push_back(bestI);
  }

  cout << sol.size() - 1 << '\n';
  for (int j : sol) cout << j + 1 << ' ';
}
SubtaskSumTestVerdictTimeMemory
base49/50
1Accepted0/03ms1956 KiB
2Accepted0/04ms2404 KiB
3Wrong answer0/13ms2456 KiB
4Accepted1/13ms2744 KiB
5Accepted2/22ms2700 KiB
6Accepted2/23ms2836 KiB
7Accepted2/23ms3212 KiB
8Accepted2/23ms3356 KiB
9Accepted2/23ms3440 KiB
10Accepted2/23ms3496 KiB
11Accepted2/23ms3532 KiB
12Accepted2/24ms3836 KiB
13Accepted2/23ms3836 KiB
14Accepted2/23ms4104 KiB
15Accepted2/23ms4372 KiB
16Accepted2/24ms4636 KiB
17Accepted2/24ms4820 KiB
18Accepted2/24ms5176 KiB
19Accepted2/24ms5348 KiB
20Accepted2/24ms5468 KiB
21Accepted2/24ms5744 KiB
22Accepted2/24ms5832 KiB
23Accepted2/24ms5936 KiB
24Accepted2/24ms6172 KiB
25Accepted2/24ms6240 KiB
26Accepted2/24ms6356 KiB
27Accepted2/24ms6468 KiB
28Accepted2/24ms6576 KiB