Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class ShopDatabase
- {
- public static void Main()
- {
- var flowers = new Queue<long>(Console.ReadLine()
- .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(long.Parse));
- var buckets = new Stack<long>(Console.ReadLine()
- .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(long.Parse));
- var secondNatures = new List<long>(0);
- while (true)
- {
- if (flowers.Count == 0)
- {
- Console.WriteLine(string.Join(" ", buckets));
- break;
- }
- if (buckets.Count == 0)
- {
- Console.WriteLine(string.Join(" ", flowers));
- break;
- }
- var currentFlower = flowers.Dequeue();
- var currentBucket = buckets.Pop();
- if (currentBucket > currentFlower)
- {
- var waterToAdd = currentBucket - currentFlower;
- if (buckets.Count != 0)
- {
- buckets.Push(buckets.Pop() + waterToAdd);
- }
- else
- {
- buckets.Push(waterToAdd);
- }
- }
- else if (currentFlower > currentBucket)
- {
- var difference = currentFlower - currentBucket;
- var temp = flowers.ToList();
- temp.Insert(0,difference);
- flowers = new Queue<long>(temp);
- }
- else
- {
- secondNatures.Add(currentFlower);
- }
- }
- if (secondNatures.Count != 0)
- {
- Console.WriteLine(string.Join(" ", secondNatures));
- }
- else
- {
- Console.WriteLine("None");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement