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 _02.SoftUniWaterSupplies
- {
- class Program
- {
- static void Main()
- {
- decimal water = decimal.Parse(Console.ReadLine());
- decimal[] bottles = Console.ReadLine().Split().Select(decimal.Parse).ToArray();
- decimal capacity = decimal.Parse(Console.ReadLine());
- decimal neededWater = 0;
- long index = -1;
- if (water % 2 == 0)
- {
- for (long i = 0; i < bottles.Length; i++)
- {
- neededWater = capacity - bottles[i];
- if (water >= neededWater)
- {
- bottles[i] += neededWater;
- water -= neededWater;
- }
- else
- {
- index = i;
- bottles[i] += water;
- break;
- }
- }
- if (index == -1)
- {
- Console.WriteLine("Enough water!");
- Console.WriteLine("Water left: {0}l.", water);
- }
- else
- {
- long bottlesCount = bottles.Where(bottle => bottle < capacity).Count();
- List<long> indexex = new List<long>();
- decimal waterShortage = 0;
- for (long i = index; i < bottles.Length; i++)
- {
- indexex.Add(i);
- waterShortage += capacity - bottles[i];
- }
- Console.WriteLine("We need more water!");
- Console.WriteLine("Bottles left: {0}", bottlesCount);
- Console.WriteLine("With indexes: {0}", string.Join(", ", indexex));
- Console.WriteLine("We need {0} more liters!", waterShortage);
- }
- }
- else
- {
- for (long i = bottles.Length - 1; i >= 0; i--)
- {
- neededWater = capacity - bottles[i];
- if (water >= neededWater)
- {
- bottles[i] += neededWater;
- water -= neededWater;
- }
- else
- {
- index = i;
- bottles[i] += water;
- break;
- }
- }
- if (index == -1)
- {
- Console.WriteLine("Enough water!");
- Console.WriteLine("Water left: {0}l.", water);
- }
- else
- {
- long bottlesCount = bottles.Where(bottle => bottle < capacity).Count();
- List<long> indexex = new List<long>();
- decimal waterShortage = 0;
- for (int i = bottles.Length - 1; i >= 0; i--)
- {
- waterShortage += capacity - bottles[i];
- if (waterShortage > 0)
- {
- indexex.Add(i);
- }
- }
- Console.WriteLine("We need more water!");
- Console.WriteLine("Bottles left: {0}", bottlesCount);
- Console.WriteLine("With indexes: {0}", string.Join(", ", indexex));
- Console.WriteLine("We need {0} more liters!", waterShortage);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement