Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace WaterSupply
- {
- class WaterSupply
- {
- static void Main()
- {
- double litersOfWater = long.Parse(Console.ReadLine());
- double[] arr = Console.ReadLine().Split().Select(double.Parse).ToArray();
- uint bottleCapacity = uint.Parse(Console.ReadLine());
- double litersToFill = arr.Length * bottleCapacity - arr.Sum();
- if (litersOfWater >= litersToFill)
- {
- Console.WriteLine("Enough water!");
- Console.WriteLine("Water left: {0}l.", litersOfWater - litersToFill);
- }
- else
- {
- List<long> indexesOfLeft = new List<long>();
- if (litersOfWater % 2 == 0)
- {
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] < bottleCapacity)
- {
- double diff = bottleCapacity - arr[i];
- if (litersOfWater >= diff)
- {
- litersOfWater = litersOfWater - diff;
- arr[i] += diff;
- }
- else
- {
- indexesOfLeft.Add(i);
- }
- }
- }
- }
- else
- {
- for (int i = arr.Length - 1; i >= 0; i--)
- {
- if (arr[i] < bottleCapacity)
- {
- double diff = bottleCapacity - arr[i];
- if (litersOfWater >= diff)
- {
- litersOfWater = litersOfWater - diff;
- arr[i] += diff;
- }
- else
- {
- indexesOfLeft.Add(i);
- }
- }
- }
- }
- Console.WriteLine("We need more water!");
- Console.WriteLine("Bottles left: {0}", indexesOfLeft.Count);
- Console.WriteLine("With indexes: {0}", string.Join(", ", indexesOfLeft));
- Console.WriteLine("We need {0} more liters!", arr.Length * bottleCapacity - arr.Sum() - litersOfWater);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment