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 Intro
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] nums = Console.ReadLine()
- .Split(',')
- .Select(int.Parse)
- .ToArray();
- var seqNums = new Dictionary<int, List<int>>();
- for (int i = 0; i < nums.Length; i++)
- {
- int currentNum = nums[i];
- seqNums.Add(i, new List<int>() { currentNum });
- int prevIndex = -1;
- int prevCount = -1;
- for (int j = 0; j < i; j++)
- {
- int num = nums[j];
- int count = seqNums[j].Count;
- if (num < currentNum && prevCount < count)
- {
- prevIndex = j;
- prevCount = count;
- }
- }
- if (prevIndex >= 0)
- {
- seqNums[i].AddRange(seqNums[prevIndex]);
- }
- }
- int maxSeqCount = seqNums.Max(s => s.Value.Count);
- var longestSeq = seqNums.First(s => s.Value.Count == maxSeqCount).Value;
- longestSeq.Reverse();
- Console.WriteLine(string.Join(",", longestSeq));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement