Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace matrixretakeexamadvanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- Stack<int> hats = new Stack<int>(Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse));
- Queue<int> scarf = new Queue<int>(Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse));
- List<int> sets = new List<int>();
- while (hats.Count != 0 && scarf.Count != 0)
- {
- int currHat = hats.Peek();
- int currScarf = scarf.Peek();
- if(currHat > currScarf)
- {
- sets.Add(hats.Pop() + scarf.Dequeue());
- }
- else if(currScarf > currHat)
- {
- hats.Pop();
- continue;
- }
- else if(currHat == currScarf)
- {
- scarf.Dequeue();
- hats.Pop();
- currHat += 1;
- hats.Push(currHat);
- }
- }
- int biggerSet = sets.Max();
- Console.WriteLine($"The most expensive set is: {biggerSet}");
- Console.WriteLine(string.Join(" ", sets));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement