199862025-12-30 21:39:19szabelrA lehető legkevesebb átszállás (50 pont)cpp17Runtime error 48/5064ms32000 KiB
// A lehető legkevesebb átszállás.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> allomasok(n + 1);
	for (int i = 1; i <= n; i++)
	{
		int x, y;
		cin >> x >> y;
		allomasok[i].first = x;
		allomasok[i].second = y;
	}
	vector<int>res;
	int most = 1;
	int index = 1;
	while (most < m)
	{
		int i = index;
		int maxi=allomasok[i].second, maxil = i;
		while (i<m and allomasok[i + 1].first <= most)
		{
			if (allomasok[i + 1].second > maxi)
			{
				maxi = allomasok[i + 1].second;
				maxil = i + 1;
			}
			i++;
		}
		res.push_back(maxil);
		index = maxil;
		most = allomasok[maxil].second;
	}
	cout << res.size() - 1 << endl;
	for (auto x : res)
		cout << x << " ";
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base48/50
1Accepted0/01ms316 KiB
2Accepted0/08ms316 KiB
3Runtime error0/159ms32000 KiB
4Runtime error0/164ms32000 KiB
5Accepted2/21ms332 KiB
6Accepted2/21ms500 KiB
7Accepted2/21ms316 KiB
8Accepted2/22ms500 KiB
9Accepted2/22ms608 KiB
10Accepted2/23ms316 KiB
11Accepted2/23ms508 KiB
12Accepted2/24ms316 KiB
13Accepted2/22ms508 KiB
14Accepted2/22ms316 KiB
15Accepted2/23ms316 KiB
16Accepted2/24ms316 KiB
17Accepted2/26ms316 KiB
18Accepted2/26ms556 KiB
19Accepted2/27ms468 KiB
20Accepted2/27ms316 KiB
21Accepted2/27ms352 KiB
22Accepted2/28ms316 KiB
23Accepted2/27ms560 KiB
24Accepted2/27ms508 KiB
25Accepted2/27ms316 KiB
26Accepted2/27ms480 KiB
27Accepted2/27ms476 KiB
28Accepted2/27ms316 KiB