Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- double totalWater = double.Parse(Console.ReadLine());
- double[] bottlesIncome = Console.ReadLine().Split().Select(double.Parse).ToArray();
- double bootleCapacity = double.Parse(Console.ReadLine());
- double totalCapacity = bottlesIncome.Length * bootleCapacity;
- double waterInBottles = totalCapacity - bottlesIncome.Sum();
- if (waterInBottles <= totalWater) ///Enough water
- {
- Console.WriteLine("Enough water!");
- Console.WriteLine("Water left: {0}l.", totalWater - waterInBottles);
- }
- else //Not enough water
- {
- double notEnoughtCapacity = totalCapacity - totalWater;
- int ostatak = (int)notEnoughtCapacity % (int)bootleCapacity;
- int bootles;
- if (ostatak == 0)
- {
- bootles = (int)notEnoughtCapacity / (int)bootleCapacity;
- }
- else
- {
- bootles = (int)notEnoughtCapacity / (int)bootleCapacity;
- bootles++;
- }
- int[] x = new int[bootles];
- if ((int)totalWater % 2 == 0) //even
- {
- int plus = bottlesIncome.Length - bootles;
- for (int i = bootles - 1; i >= 0; i--) // show direction of filing from left to right
- {
- x[i] = i + plus;
- }
- }
- else//odd
- {
- for (int i = bootles - 1; i >= 0; i--) // show direction of filing from right to left
- {
- x[i] = bootles - 1 - i;
- }
- }
- Console.WriteLine("We need more water!");
- Console.WriteLine("Bottles left: {0}", bootles);
- Console.WriteLine("With indexes: {0}", string.Join(", ", x));
- Console.WriteLine("We need {0} more liters!", notEnoughtCapacity);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement