199872025-12-30 21:41:04szabelrA lehető legkevesebb átszállás (50 pont)cpp17Wrong answer 34/508ms508 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 (maxil == index)
		{
			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
SubtaskSumTestVerdictTimeMemory
base34/50
1Accepted0/01ms508 KiB
2Wrong answer0/07ms508 KiB
3Accepted1/11ms316 KiB
4Accepted1/11ms316 KiB
5Accepted2/21ms316 KiB
6Wrong answer0/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/22ms412 KiB
9Accepted2/22ms316 KiB
10Accepted2/23ms508 KiB
11Accepted2/24ms428 KiB
12Accepted2/24ms316 KiB
13Accepted2/21ms316 KiB
14Accepted2/22ms316 KiB
15Accepted2/23ms316 KiB
16Wrong answer0/24ms316 KiB
17Accepted2/24ms316 KiB
18Accepted2/26ms508 KiB
19Accepted2/27ms316 KiB
20Accepted2/27ms464 KiB
21Accepted2/27ms472 KiB
22Accepted2/27ms508 KiB
23Wrong answer0/27ms500 KiB
24Wrong answer0/27ms508 KiB
25Wrong answer0/27ms316 KiB
26Wrong answer0/27ms316 KiB
27Wrong answer0/27ms316 KiB
28Wrong answer0/28ms316 KiB