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;
- using System.Threading.Tasks;
- namespace _2
- {
- class Program
- {
- static void Main(string[] args)
- {
- decimal amountOfWater = decimal.Parse(Console.ReadLine());
- decimal[] bottlesToFill = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
- int capacityOfBottles =int.Parse(Console.ReadLine());
- List<int> bottToFill = new List<int>();
- if (amountOfWater%2==0)
- {
- for (int i = 0; i < bottlesToFill.Length; i++)
- {
- if (bottlesToFill[i]==capacityOfBottles)
- {
- continue;
- }
- else
- {
- decimal checkForWater = amountOfWater-(capacityOfBottles-bottlesToFill[i]);
- if (checkForWater>0)
- {
- decimal litters = bottlesToFill[i];
- bottlesToFill[i]+=capacityOfBottles-litters;
- amountOfWater-=capacityOfBottles-litters;
- }
- else if (amountOfWater>0)
- {
- bottlesToFill[i]+=amountOfWater;
- amountOfWater=0;
- }
- }
- if (amountOfWater==0)
- {
- for (int h = 0; h < bottlesToFill.Length; h++)
- {
- if (bottlesToFill[h]<capacityOfBottles)
- {
- bottToFill.Add(h);
- }
- }
- break;
- }
- }
- }
- if (amountOfWater%2!=0)
- {
- for (int i = bottlesToFill.Length-1; i >= 0; i--)
- {
- if (bottlesToFill[i]==capacityOfBottles)
- {
- break;
- }
- else
- {
- decimal checkForWater = amountOfWater-(capacityOfBottles-bottlesToFill[i]);
- if (checkForWater>0)
- {
- decimal litters = bottlesToFill[i];
- bottlesToFill[i]+=capacityOfBottles-litters;
- amountOfWater-=capacityOfBottles-litters;
- }
- else if (amountOfWater>0)
- {
- bottlesToFill[i]+=amountOfWater;
- amountOfWater=0;
- }
- }
- if (amountOfWater==0)
- {
- for (int h = bottlesToFill.Length-1; h >= 0; h--)
- {
- if (bottlesToFill[h]<capacityOfBottles)
- {
- bottToFill.Add(h);
- }
- }
- break;
- }
- }
- }
- int checkForList = bottToFill.Count;
- if (checkForList==0)
- {
- Console.WriteLine("Enough water!\nWater left: {0}l.",amountOfWater);
- }
- else
- {
- decimal waterNeed = 0;
- for (int i = 0; i < bottToFill.Count; i++)
- {
- int index = bottToFill[i];
- if (bottlesToFill[index]<capacityOfBottles)
- {
- waterNeed+=capacityOfBottles-bottlesToFill[index];
- }
- }
- Console.WriteLine("We need more water!\nBottles left: {0}\nWith indexes: {1}\nWe need {2} more liters!",checkForList,string.Join(", ",bottToFill),waterNeed);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement