Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- public class Program
- {
- public static void Main()
- {
- int[] leftSocksInput = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int[] rightSocksInput = Console.ReadLine().Split().Select(int.Parse).ToArray();
- List<int> result = new List<int>();
- Stack<int> leftSocks = new Stack<int>(leftSocksInput);
- Queue<int> rightSocks = new Queue<int>(rightSocksInput);
- while (leftSocks.Any() && rightSocks.Any())
- {
- int currLeft = leftSocks.Peek();
- int currRight = rightSocks.Peek();
- if(currLeft>currRight)
- {
- int sum = currLeft + currRight;
- result.Add(sum);
- leftSocks.Pop();
- rightSocks.Dequeue();
- }
- else if (currLeft<currRight)
- {
- leftSocks.Pop();
- }
- else
- {
- rightSocks.Dequeue();
- currLeft+=1;
- leftSocks.Pop();
- leftSocks.Push(currLeft);
- }
- }
- Console.WriteLine(result.Max());
- Console.WriteLine(string.Join(" ",result));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment