199882025-12-30 21:41:59szabelrA lehető legkevesebb átszállás (50 pont)cpp17Futási hiba 48/5076ms32000 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;
	bool possible = true;
	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);
		if (maxi == allomasok[i].first)
		{
			possible = false;
			break;
		}
		index = maxil;
		most = allomasok[maxil].second;
	}
	if (possible)
	{
		cout << res.size() - 1 << endl;
		for (auto x : res)
			cout << x << " ";
	}
	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
base48/50
1Elfogadva0/01ms508 KiB
2Elfogadva0/07ms316 KiB
3Futási hiba0/176ms32000 KiB
4Futási hiba0/171ms32000 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/21ms316 KiB
7Elfogadva2/21ms316 KiB
8Elfogadva2/22ms316 KiB
9Elfogadva2/22ms316 KiB
10Elfogadva2/22ms424 KiB
11Elfogadva2/23ms428 KiB
12Elfogadva2/24ms316 KiB
13Elfogadva2/21ms316 KiB
14Elfogadva2/22ms416 KiB
15Elfogadva2/23ms316 KiB
16Elfogadva2/24ms316 KiB
17Elfogadva2/24ms456 KiB
18Elfogadva2/26ms460 KiB
19Elfogadva2/26ms472 KiB
20Elfogadva2/26ms316 KiB
21Elfogadva2/27ms344 KiB
22Elfogadva2/27ms316 KiB
23Elfogadva2/27ms500 KiB
24Elfogadva2/27ms508 KiB
25Elfogadva2/27ms316 KiB
26Elfogadva2/27ms476 KiB
27Elfogadva2/27ms636 KiB
28Elfogadva2/28ms316 KiB