57662023-09-21 09:44:10zsebiA lehető legkevesebb átszállás (50 pont)cpp11Wrong answer 2/509ms4932 KiB
// leheto legk atszallas.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>
#include <algorithm>
#define ll long long 
using namespace std;

ll n, k,kezd, veg,a,b;
int main()
{
    cin >> n>>k;
    deque<pair<ll, ll>>x;
    vector<ll>ans;
   
    for (int i = 0; i < n; ++i)
    {
        cin >> a >> b;
        x.push_back({ a,b });
    }
    sort(x.begin(), x.end(), [](pair<ll, ll>a, pair<ll, ll>b)
        {
            if (a.first < b.first)return true;
            else if (a.first==b.first &&a.second > b.second) return true;
    return false;
        });
    kezd = 1, veg = 1;
    int i = 1;
    bool ok2 = false,ok3=false;
    while (i<n)
    {
        
        bool ok = false;
        pair<ll, ll>a = x[i];
        if (a.first == 1)ok2 = true;
        if (a.first <= veg && a.second > veg)
        {
            veg = a.second;
            ans.push_back(i+1);
        }
        if (veg == k)ok3 = true;
        while (i<n&&x[i].first == a.first)
        {
            ok = true;
            ++i;
        }
        if (!ok)++i;
        }
    if (!ok2 || !ok3)
    {
        cout << "-1";
        return 0;
    }
    cout << ans.size() - 1 << "\n";
    for (auto& e : ans)cout << e << " ";
    return 0;
}

// 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
base2/50
1Accepted0/03ms1808 KiB
2Wrong answer0/09ms2452 KiB
3Accepted1/13ms2308 KiB
4Accepted1/12ms2404 KiB
5Wrong answer0/22ms2636 KiB
6Wrong answer0/22ms2752 KiB
7Wrong answer0/23ms2860 KiB
8Wrong answer0/23ms3096 KiB
9Wrong answer0/24ms3064 KiB
10Wrong answer0/24ms3348 KiB
11Wrong answer0/24ms3324 KiB
12Wrong answer0/26ms3384 KiB
13Wrong answer0/23ms3436 KiB
14Wrong answer0/24ms3500 KiB
15Wrong answer0/24ms3516 KiB
16Wrong answer0/26ms3820 KiB
17Wrong answer0/28ms4076 KiB
18Wrong answer0/28ms4200 KiB
19Wrong answer0/28ms4472 KiB
20Wrong answer0/28ms4432 KiB
21Wrong answer0/29ms4508 KiB
22Wrong answer0/29ms4476 KiB
23Wrong answer0/28ms4444 KiB
24Wrong answer0/28ms4764 KiB
25Wrong answer0/28ms4668 KiB
26Wrong answer0/28ms4820 KiB
27Wrong answer0/28ms4932 KiB
28Wrong answer0/28ms4884 KiB