Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _2.SoftUni_Water_Supplies
- {
- class Program
- {
- static void Main()
- {
- double water = double.Parse(Console.ReadLine());
- List<double> bottles = Console.ReadLine().Split(' ').Select(double.Parse).ToList();
- long capacity = long.Parse(Console.ReadLine());
- var indexes = new List<int>();
- double initialQuantity = water;
- int currentIndex = water % 2 == 0 ? 0 : bottles.Count - 1;
- while (currentIndex != -1 && currentIndex < bottles.Count)
- {
- var bottleLiters = bottles[currentIndex];
- if (bottles[currentIndex] < capacity)
- {
- bottles[currentIndex]+= capacity - bottleLiters;
- water -= capacity - bottleLiters;
- if (water < 0) { indexes.Add(currentIndex); }
- }
- currentIndex = initialQuantity % 2 == 0 ? ++currentIndex : --currentIndex;
- }
- if (water >= 0)
- {
- Console.WriteLine($"Enough water!\nWater left: {water}l.");
- }
- else
- {
- Console.WriteLine("We need more water!");
- Console.WriteLine($"Bottles left: {indexes.Count}");
- Console.WriteLine("With indexes: {0}", string.Join(", ", indexes));
- Console.WriteLine($"We need {Math.Abs(water)} more liters!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement