Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Olimpic
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberTests = int.Parse(Console.ReadLine());
- for (int i = 0; i < numberTests; i++)
- {
- int requiredQuantity;
- int bottleQuantity;
- int sinkQuantity;
- bool hasSuccess = false;
- int[] commands = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- bottleQuantity = commands[0];
- sinkQuantity = commands[1];
- requiredQuantity = commands[2];
- Stack<int> sink = new Stack<int>(sinkQuantity);
- Stack<int> bottle = new Stack<int>(bottleQuantity);
- int leftInTheBottle = 0;
- int count = 0;
- int bottleCount = 0;
- int sinkCount = 0;
- bool a = false;
- if (requiredQuantity > bottleQuantity)
- {
- while (requiredQuantity>bottleQuantity)
- {
- bottleCount++;
- requiredQuantity -= bottleQuantity;
- }
- a = true;
- }
- while (true)
- {
- if (bottle.Count ==requiredQuantity )
- {
- hasSuccess = true;
- break;
- }
- else
- {
- for (int m = 0; m < bottle.Count; m++)
- {
- sink.Push(bottle.Pop());
- m--;
- }
- }
- bool hasFill = false;
- for (int j = 0; j < bottleQuantity; j++)
- {
- if (bottle.Count == bottleQuantity) { break; }
- else
- {
- bottle.Push(1);
- hasFill = true;
- }
- }
- if (hasFill)
- {
- bottleCount++;
- }
- for (int m = 0; m < bottle.Count; m++)
- {
- if (sink.Count == sinkQuantity)
- {
- leftInTheBottle = bottle.Count;
- sink.Clear();
- sinkCount++;
- break;
- }
- else
- {
- sink.Push(bottle.Pop());
- m--;
- }
- }
- if (count == 1000000)
- {
- break;
- }
- count++;
- }
- if (hasSuccess)
- {
- if (a)
- {
- Console.WriteLine($"{bottleCount} {sinkCount}");
- }
- else
- {
- Console.WriteLine($"{bottleCount} {sinkCount}");
- }
- }
- else
- {
- Console.WriteLine("IMPOSSIBLE");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment