Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02_SoftUniWaterSupplies
- {
- class SoftUniWaterSupplies
- {
- static void Main(string[] args)
- {
- decimal waterTotal = decimal.Parse(Console.ReadLine());
- var array = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
- decimal capacity = decimal.Parse(Console.ReadLine());
- var currIndexes = new List<int>();
- var currFilledBottles = new List<decimal>(array);
- decimal waterCurrent = waterTotal;
- var waterToFill = 0m;
- if (waterTotal % 2 == 0)
- {
- for (int i = 0; i < array.Length; i++)
- {
- if (waterCurrent < 0)
- {
- break;
- }
- waterToFill = capacity - array[i];
- waterCurrent -= waterToFill;
- if (waterCurrent >= 0)
- {
- currFilledBottles[i] = currFilledBottles[i] + waterToFill;
- }
- else
- {
- currFilledBottles[i] = currFilledBottles[i] + (waterToFill + waterCurrent);
- }
- }
- }
- else
- {
- int counter = 1;
- for (int i = array.Length - 1; i >= 0; i--)
- {
- if (waterCurrent < 0)
- {
- break;
- }
- waterToFill = capacity - array[i];
- waterCurrent -= waterToFill;
- if (waterCurrent >= 0)
- {
- currFilledBottles[array.Length - counter] = currFilledBottles[array.Length - counter] + waterToFill;
- counter++;
- }
- else
- {
- currFilledBottles[array.Length - counter] = currFilledBottles[array.Length - counter] + (waterToFill + waterCurrent);
- }
- }
- }
- for (int i = 0; i < array.Length; i++)
- {
- if (currFilledBottles[i] < capacity)
- {
- currIndexes.Add(i);
- }
- }
- int bottlesCount = currFilledBottles.Where(x => x < capacity).Count();
- if (waterCurrent >= 0)
- {
- Console.WriteLine("Enough water!");
- Console.WriteLine($"Water left: {waterCurrent}l.");
- }
- else
- {
- currIndexes.Reverse();
- currFilledBottles = currFilledBottles.Where(x => x != capacity).ToList();
- var nededWater = capacity * currFilledBottles.Count - currFilledBottles.Sum();
- Console.WriteLine("We need more water!");
- Console.WriteLine($"Bottles left: {bottlesCount}");
- Console.Write("With indexes: ");
- Console.WriteLine(String.Join(", ", currIndexes));
- Console.WriteLine($"We need {nededWater} more liters!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement