76672024-01-10 11:21:42NotYouA lehető legkevesebb átszállás (50 pont)csharpWrong answer 16/5054ms31288 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atszallas
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int vs = s[0];
            int asz = s[1];
            List<int> kezd = new List<int>();
            List<int> veg = new List<int>();
            int iv = 0;
            bool vv = false;
            int kezdi = 0;
            int at = 0;
            List<int> vh = new List<int>();

            for (int i = 0; i < vs; i++)
            {
                int[] s1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
                kezd.Add(s1[0]);
                veg.Add(s1[1]);

                if (kezd[i] == 1 && iv < kezd [i])
                {
                    iv = veg[i];
                    kezdi = i;
                    at++;
                }

                if (veg[i] == asz)
                {
                   vv = true;
                }
            }
            
            
            if (iv == 0 || vv == false)
            {
                Console.WriteLine(-1);
            }
            else
            {
                List<int> vsz = new List<int>();
                int max = 0;
                int maxi = 0;
                int cv = 0;
                while (kezd[cv]==1)
                {
                    if (veg[cv]>max)
                    {
                        max = veg[cv];
                        maxi = cv+1;
                    }
                    cv++;
                }

                //Console.WriteLine(maxi);
                vsz.Add(maxi);
                int maxveg = max;
                int maxvegi = cv;
                for (int i = cv; i < vs; i++)
                {
                    if (kezd[i] <= max)
                    {
                        if (maxveg <veg[i])
                        {
                            maxveg = veg[i];
                            maxvegi = i;
                        }
                        
                    }
                    else
                    {
                        vsz.Add(maxvegi + 1);
                        max = maxveg;
                        maxvegi = i;

                    }
                }
                if (vsz[vsz.Count-1] != maxvegi-1)
                {
                    vsz.Add(maxvegi + 1);
                }
                bool hiba = false;
                for (int i = 1; i < vsz.Count; i++)
                {
                    if (veg[vsz[i-1]-1]<kezd[vsz[i]-1])
                    {
                        hiba = true;
                    }
                }
                if (hiba == true)
                {
                    Console.WriteLine(-1);
                }
                else
                {
                    Console.WriteLine(vsz.Count-1);
                    Console.WriteLine(string.Join(" ", vsz));
                }

            }
            Console.ReadLine();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base16/50
1Wrong answer0/035ms22300 KiB
2Wrong answer0/054ms27968 KiB
3Accepted1/132ms22752 KiB
4Accepted1/132ms23216 KiB
5Accepted2/232ms23600 KiB
6Accepted2/235ms24044 KiB
7Wrong answer0/235ms24736 KiB
8Wrong answer0/235ms25564 KiB
9Wrong answer0/237ms25920 KiB
10Wrong answer0/239ms26012 KiB
11Wrong answer0/243ms26504 KiB
12Wrong answer0/243ms27136 KiB
13Wrong answer0/237ms25336 KiB
14Accepted2/237ms25644 KiB
15Wrong answer0/239ms26700 KiB
16Wrong answer0/241ms27396 KiB
17Wrong answer0/248ms28788 KiB
18Wrong answer0/248ms29160 KiB
19Wrong answer0/248ms29664 KiB
20Wrong answer0/248ms30568 KiB
21Wrong answer0/252ms30412 KiB
22Wrong answer0/252ms30500 KiB
23Accepted2/252ms30496 KiB
24Accepted2/252ms30852 KiB
25Wrong answer0/252ms30748 KiB
26Accepted2/250ms31288 KiB
27Accepted2/252ms31220 KiB
28Wrong answer0/254ms31016 KiB