Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _05.IncreasingCrisis
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Program
- {
- static List<int> sequence = new List<int>();
- public static void Main()
- {
- int numOfLines = int.Parse(Console.ReadLine());
- List<int> sequence = new List<int>(0);
- for (int i = 0; i < numOfLines; i++)
- {
- List<int> currentSequence = Console.ReadLine()
- .Split(new [] { (' ') }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse).ToList();
- int index = 0;
- if (sequence.Count == 0)
- {
- sequence.AddRange(currentSequence);
- }
- else
- {
- for (int find = 0; find < sequence.Count; find++)
- {
- if (sequence[find] <= currentSequence[0])
- {
- index++;
- }
- else
- {
- break;
- }
- }
- sequence.InsertRange(index, currentSequence);
- index = 0;
- bool isBroken = false;
- for (int broken = 1; broken < sequence.Count; broken++)
- {
- if (sequence[broken - 1] > sequence[broken])
- {
- isBroken = true;
- index = broken;
- break;
- }
- }
- if (isBroken)
- {
- sequence.RemoveRange(index, sequence.Count - index);
- }
- }
- }
- Console.WriteLine(string.Join(" ", sequence));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement