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 ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int length = int.Parse(Console.ReadLine());
- int[] bestArr = new int[length];
- int sequenceCounter = 0;
- string arr = Console.ReadLine();
- int maxSubSeqLen = 0;
- int maxSubSeqSum = 0;
- int bestStartPos = 0;
- int bestArrSum = 0;
- int counter = 0;
- while (arr != "Clone them!")
- {
- int[] currentArr = arr.Split('!').Select(int.Parse).ToArray();
- int currentArrSum = 0;
- sequenceCounter++;
- int currentStartPosition = 0;
- int currentLength = 0;
- for (int i = 0; i < length; i++)
- {
- currentArrSum += currentArr[i];
- if (currentArr[i] == 1)
- {
- currentLength++;
- currentStartPosition = i;
- }
- if (currentLength > maxSubSeqLen || (currentLength == maxSubSeqLen && currentStartPosition < bestStartPos) || (currentLength == maxSubSeqLen && currentStartPosition == bestStartPos && currentArrSum > maxSubSeqSum))
- {
- maxSubSeqLen = currentLength;
- maxSubSeqSum = currentArrSum;
- bestArr = currentArr;
- bestArrSum = currentArrSum;
- counter = sequenceCounter;
- bestStartPos = currentStartPosition;
- }
- }
- currentLength = 0;
- currentStartPosition = 0;
- currentArrSum = 0;
- arr = Console.ReadLine();
- }
- Console.WriteLine("Best DNA sample {0} with sum: {1}.", counter, maxSubSeqSum);
- Console.WriteLine(string.Join(" ", bestArr));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement