97392024-03-05 09:30:09phiterrA lehető legkevesebb átszállás (50 pont)cpp17Accepted 50/5010ms6520 KiB
#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int linesNum = 0;
	int stationsNum = 0;
	cin >> linesNum;
	cin >> stationsNum;
	vector<pair<int, int>> stations(stationsNum, { 0,0 });
	for (int i = 0; i < linesNum; i++) {
		int start = 0;
		int end = 0;
		cin >> start >> end;
		for (int j = start - 1; j < end -1; j++) {
			if (stations[j].second < end) {
				stations[j] = pair<int, int>(i, end - 1);

			}
			else break;
		}

	}
	vector<int> takenLines(0, 0);
	for (int i = 0; i + 1 < stationsNum; i) {
		if (stations[i] == pair<int, int>(0, 0)) {
			
				cout << -1;
				return 0;
			
		}else {
			takenLines.push_back(stations[i].first);
			i = stations[i].second;
		}
	}
	cout << takenLines.size() - 1 << endl;
		for (int i : takenLines) {
			cout << i + 1 << ' ';
		}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1964 KiB
2Accepted0/010ms3612 KiB
3Accepted1/13ms2380 KiB
4Accepted1/13ms2440 KiB
5Accepted2/23ms2656 KiB
6Accepted2/22ms2740 KiB
7Accepted2/23ms2900 KiB
8Accepted2/24ms2928 KiB
9Accepted2/24ms3092 KiB
10Accepted2/24ms3312 KiB
11Accepted2/26ms3424 KiB
12Accepted2/26ms3604 KiB
13Accepted2/23ms3676 KiB
14Accepted2/24ms3784 KiB
15Accepted2/24ms4604 KiB
16Accepted2/27ms4516 KiB
17Accepted2/28ms5140 KiB
18Accepted2/28ms5388 KiB
19Accepted2/29ms5504 KiB
20Accepted2/29ms5776 KiB
21Accepted2/210ms5728 KiB
22Accepted2/210ms5848 KiB
23Accepted2/29ms5444 KiB
24Accepted2/29ms5812 KiB
25Accepted2/210ms6056 KiB
26Accepted2/210ms6168 KiB
27Accepted2/210ms6404 KiB
28Accepted2/210ms6520 KiB