79832024-01-12 09:40:27250L7A lehető legkevesebb átszállás (50 pont)cpp17Runtime error 49/5071ms64424 KiB
// vonat.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int vonat, allom;
	cin >> vonat >> allom;
	vector <pair<int, int>> megall(vonat);
	for (int i = 0; i < vonat; i++)
	{
		cin >> megall[i].first >> megall[i].second;
	}
	int helymax = 1;
	int x = 0;
	int atszall = 0;
	int maxi = 0, maxihely = 0;
	vector <int> ut;
	int xd = 0;
	while (x < vonat && helymax != allom)
	{
		//cout << "n";
		while (x < vonat && megall[x].first <= helymax)
		{
			if (megall[x].second > maxi)
			{
				maxi = megall[x].second;
				maxihely = x;
			}
			x++;
		}
		helymax = maxi;
		ut.push_back(maxihely+1);
		atszall++;
		xd++;
		if (xd == 10000000)
		{
			cout << "-1";
			return 0;
		}
	}
	if (helymax == allom)
	{
		cout << atszall - 1 << endl;
		for (int i = 0; i < ut.size(); i++)
		{
			cout << ut[i] << " ";
		}
	}
	else {
		cout << "-1";
	}
}

// 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
base49/50
1Accepted0/03ms1812 KiB
2Accepted0/08ms2260 KiB
3Accepted1/13ms2272 KiB
4Runtime error0/171ms64424 KiB
5Accepted2/23ms2660 KiB
6Accepted2/23ms2880 KiB
7Accepted2/23ms2972 KiB
8Accepted2/24ms3124 KiB
9Accepted2/24ms3124 KiB
10Accepted2/24ms3156 KiB
11Accepted2/24ms3292 KiB
12Accepted2/26ms3532 KiB
13Accepted2/23ms3592 KiB
14Accepted2/24ms3812 KiB
15Accepted2/24ms3848 KiB
16Accepted2/26ms3944 KiB
17Accepted2/27ms4224 KiB
18Accepted2/28ms4332 KiB
19Accepted2/28ms4184 KiB
20Accepted2/28ms4192 KiB
21Accepted2/28ms4196 KiB
22Accepted2/28ms4240 KiB
23Accepted2/28ms4380 KiB
24Accepted2/28ms4200 KiB
25Accepted2/28ms4344 KiB
26Accepted2/28ms4200 KiB
27Accepted2/28ms4196 KiB
28Accepted2/28ms4200 KiB