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;
- namespace Advance
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] cupCapacity = Console.ReadLine().Split().Reverse(). Select(int.Parse).ToArray();
- int[] BottleCapacity = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int amount = 0;
- Stack<int> cupStack = new Stack<int>(cupCapacity);
- Stack<int> BottleStack = new Stack<int>(BottleCapacity);
- while (BottleStack.Any() && cupStack.Any())
- {
- int currentCup = cupStack.Pop();
- int currentbottle = BottleStack.Pop();
- if ( currentbottle >= currentCup)
- {
- amount += currentbottle - currentCup;
- }
- else if ( currentCup > currentbottle)
- { if (BottleStack.Count > 0)
- {
- amount += BottleStack.Pop() - (currentCup - currentbottle);
- }
- else
- {
- amount += currentbottle;
- cupStack.Push(currentCup);
- }
- }
- }
- if (cupStack.Any())
- {
- Console.WriteLine($"Cups: {string.Join(" ",cupStack)}");
- Console.WriteLine($"Wasted litters of water: {amount}");
- }
- else if ( BottleStack.Any())
- {
- Console.WriteLine($"Bottles: {string.Join(" ", BottleStack)}");
- Console.WriteLine($"Wasted litters of water: {amount}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement