7983 2024. 01. 12 09:40:27 250L7 A lehető legkevesebb átszállás (50 pont) cpp17 Futási hiba 49/50 71ms 64424 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 Összpont Teszt Verdikt Idő Memória
base 49/50
1 Elfogadva 0/0 3ms 1812 KiB
2 Elfogadva 0/0 8ms 2260 KiB
3 Elfogadva 1/1 3ms 2272 KiB
4 Futási hiba 0/1 71ms 64424 KiB
5 Elfogadva 2/2 3ms 2660 KiB
6 Elfogadva 2/2 3ms 2880 KiB
7 Elfogadva 2/2 3ms 2972 KiB
8 Elfogadva 2/2 4ms 3124 KiB
9 Elfogadva 2/2 4ms 3124 KiB
10 Elfogadva 2/2 4ms 3156 KiB
11 Elfogadva 2/2 4ms 3292 KiB
12 Elfogadva 2/2 6ms 3532 KiB
13 Elfogadva 2/2 3ms 3592 KiB
14 Elfogadva 2/2 4ms 3812 KiB
15 Elfogadva 2/2 4ms 3848 KiB
16 Elfogadva 2/2 6ms 3944 KiB
17 Elfogadva 2/2 7ms 4224 KiB
18 Elfogadva 2/2 8ms 4332 KiB
19 Elfogadva 2/2 8ms 4184 KiB
20 Elfogadva 2/2 8ms 4192 KiB
21 Elfogadva 2/2 8ms 4196 KiB
22 Elfogadva 2/2 8ms 4240 KiB
23 Elfogadva 2/2 8ms 4380 KiB
24 Elfogadva 2/2 8ms 4200 KiB
25 Elfogadva 2/2 8ms 4344 KiB
26 Elfogadva 2/2 8ms 4200 KiB
27 Elfogadva 2/2 8ms 4196 KiB
28 Elfogadva 2/2 8ms 4200 KiB