Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace increasingCrisis
- {
- class Program
- {
- static void Main(string[] args)
- {
- int lists = int.Parse(Console.ReadLine());
- List<int> finalList = new List<int>();
- for (int i = 0; i < lists; i++)
- {
- List<int> temp = Console.ReadLine().Split().Select(int.Parse).ToList();
- if (i == 0)
- {
- finalList = temp;
- }
- else
- {
- CheckList(finalList, temp);
- CleanList(ref finalList);
- }
- }
- Console.WriteLine(string.Join(" ", finalList));
- }
- static List<int> CheckList(List<int> finalList, List<int> temp)
- {
- for (int i = 0; i < finalList.Count; i++)
- {
- if(i == finalList.Count - 1 && finalList[i] <= temp[0])
- {
- finalList = AddList(finalList, temp, i);
- return finalList;
- }
- else if (finalList[i] <= temp[0] && finalList[i+1] > temp [0] )
- {
- finalList = AddList(finalList, temp, i);
- return finalList;
- }
- }
- return finalList;
- }
- static List<int> AddList(List<int> finalList, List<int> temp, int number)
- {
- for (int i = 0; i < temp.Count; i++)
- {
- finalList.Insert(number + i +1 , temp[i]);
- }
- return finalList;
- }
- static List<int> CleanList(ref List<int> finalList)
- {
- List<int> newList = new List<int>();
- for (int i = 0; i <= finalList.Count-1; i++)
- {
- if(i == finalList.Count-1 && finalList[i]> finalList[i-1])
- {
- newList.Add(finalList[i]);
- }
- else if(finalList[i] > finalList[i + 1] )
- {
- newList.Add(finalList[i]);
- break;
- }
- else
- {
- newList.Add(finalList[i]);
- }
- }
- finalList = newList;
- return finalList;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement