bullit3189

Socks

Jun 10th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. public class Program
  7. {
  8. public static void Main()
  9. {
  10. int[] leftSocksInput = Console.ReadLine().Split().Select(int.Parse).ToArray();
  11. int[] rightSocksInput = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.  
  13. List<int> result = new List<int>();
  14.  
  15. Stack<int> leftSocks = new Stack<int>(leftSocksInput);
  16. Queue<int> rightSocks = new Queue<int>(rightSocksInput);
  17.  
  18. while (leftSocks.Any() && rightSocks.Any())
  19. {
  20. int currLeft = leftSocks.Peek();
  21. int currRight = rightSocks.Peek();
  22.  
  23. if(currLeft>currRight)
  24. {
  25. int sum = currLeft + currRight;
  26. result.Add(sum);
  27. leftSocks.Pop();
  28. rightSocks.Dequeue();
  29. }
  30. else if (currLeft<currRight)
  31. {
  32. leftSocks.Pop();
  33. }
  34. else
  35. {
  36. rightSocks.Dequeue();
  37. currLeft+=1;
  38. leftSocks.Pop();
  39. leftSocks.Push(currLeft);
  40. }
  41. }
  42.  
  43. Console.WriteLine(result.Max());
  44. Console.WriteLine(string.Join(" ",result));
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment