57112023-09-09 18:36:30TomaSajtA lehető legkevesebb átszállás (50 pont)cpp17Accepted 50/504ms4652 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) break;
    pos = lines[bestI].e;
    sol.push_back(bestI);
  }

  if (pos < m) {
    cout << "-1";
    return 0;
  }

  cout << sol.size() - 1 << '\n';
  for (int j : sol) cout << j + 1 << ' ';
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1824 KiB
2Accepted0/04ms2292 KiB
3Accepted1/13ms2244 KiB
4Accepted1/12ms2472 KiB
5Accepted2/22ms2684 KiB
6Accepted2/22ms2892 KiB
7Accepted2/23ms3120 KiB
8Accepted2/23ms3336 KiB
9Accepted2/23ms3680 KiB
10Accepted2/23ms3752 KiB
11Accepted2/23ms3972 KiB
12Accepted2/23ms3916 KiB
13Accepted2/23ms4016 KiB
14Accepted2/23ms4104 KiB
15Accepted2/23ms4116 KiB
16Accepted2/23ms4028 KiB
17Accepted2/24ms4296 KiB
18Accepted2/24ms4264 KiB
19Accepted2/24ms4524 KiB
20Accepted2/24ms4480 KiB
21Accepted2/24ms4512 KiB
22Accepted2/24ms4500 KiB
23Accepted2/24ms4496 KiB
24Accepted2/24ms4500 KiB
25Accepted2/24ms4628 KiB
26Accepted2/24ms4652 KiB
27Accepted2/24ms4632 KiB
28Accepted2/24ms4648 KiB