Advertisement
osman1997

Untitled

Apr 14th, 2021
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace matrixretakeexamadvanced
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Stack<int> hats = new Stack<int>(Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse));
  12. Queue<int> scarf = new Queue<int>(Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse));
  13.  
  14. List<int> sets = new List<int>();
  15.  
  16. while (hats.Count != 0 && scarf.Count != 0)
  17. {
  18. int currHat = hats.Peek();
  19. int currScarf = scarf.Peek();
  20.  
  21. if(currHat > currScarf)
  22. {
  23. sets.Add(hats.Pop() + scarf.Dequeue());
  24. }
  25. else if(currScarf > currHat)
  26. {
  27. hats.Pop();
  28.  
  29. continue;
  30. }
  31. else if(currHat == currScarf)
  32. {
  33. scarf.Dequeue();
  34. hats.Pop();
  35. currHat += 1;
  36. hats.Push(currHat);
  37. }
  38. }
  39.  
  40. int biggerSet = sets.Max();
  41.  
  42. Console.WriteLine($"The most expensive set is: {biggerSet}");
  43.  
  44.  
  45. Console.WriteLine(string.Join(" ", sets));
  46.  
  47.  
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement