79832024-01-12 09:40:27250L7A lehető legkevesebb átszállás (50 pont)cpp17Futási hiba 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base49/50
1Elfogadva0/03ms1812 KiB
2Elfogadva0/08ms2260 KiB
3Elfogadva1/13ms2272 KiB
4Futási hiba0/171ms64424 KiB
5Elfogadva2/23ms2660 KiB
6Elfogadva2/23ms2880 KiB
7Elfogadva2/23ms2972 KiB
8Elfogadva2/24ms3124 KiB
9Elfogadva2/24ms3124 KiB
10Elfogadva2/24ms3156 KiB
11Elfogadva2/24ms3292 KiB
12Elfogadva2/26ms3532 KiB
13Elfogadva2/23ms3592 KiB
14Elfogadva2/24ms3812 KiB
15Elfogadva2/24ms3848 KiB
16Elfogadva2/26ms3944 KiB
17Elfogadva2/27ms4224 KiB
18Elfogadva2/28ms4332 KiB
19Elfogadva2/28ms4184 KiB
20Elfogadva2/28ms4192 KiB
21Elfogadva2/28ms4196 KiB
22Elfogadva2/28ms4240 KiB
23Elfogadva2/28ms4380 KiB
24Elfogadva2/28ms4200 KiB
25Elfogadva2/28ms4344 KiB
26Elfogadva2/28ms4200 KiB
27Elfogadva2/28ms4196 KiB
28Elfogadva2/28ms4200 KiB