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 SoftuniWatterSupplies
- {
- static void Main(string[] args)
- {
- double amountOfWater = int.Parse(Console.ReadLine());
- List<double> bottles = Console.ReadLine().Split().Select(double.Parse).ToList();
- double bottlesCapacity = double.Parse(Console.ReadLine());
- int bottlesLeft = 0;
- double neededL = 0;
- List<int> index = new List<int>();
- if (amountOfWater%2==0)
- {
- for (int i = 0; i < bottles.Count; i++)
- {
- while (bottles[i] != bottlesCapacity && amountOfWater != 0)
- {
- double diff = bottlesCapacity - bottles[i];
- if (diff<=amountOfWater)
- {
- bottles[i] += diff;
- amountOfWater -= diff;
- }
- }
- if (amountOfWater==0)
- {
- break;
- }
- }
- List<double> check = bottles.Where(a => a == bottlesCapacity).ToList();
- if (check.Count== bottles.Count)
- {
- Console.WriteLine("Enough water!");
- Console.WriteLine($"Water left: {amountOfWater}l.");
- }
- else
- {
- Console.WriteLine("We need more water!");
- for (int i = 0; i < bottles.Count; i++)
- {
- if (bottles[i]!=bottlesCapacity)
- {
- index.Add(i);
- bottlesLeft++;
- neededL += bottlesCapacity - bottles[i];
- }
- }
- Console.WriteLine($"Bottles left: {bottlesLeft}");
- Console.WriteLine($"With indexes: {string.Join(", ",index)}");
- Console.WriteLine($"We need {neededL} more liters!");
- }
- }
- else
- {
- for (int i = bottles.Count-1; i >=0 ; i--)
- {
- while (bottles[i] != bottlesCapacity && amountOfWater != 0)
- {
- double diff = bottlesCapacity - bottles[i];
- if (diff <= amountOfWater)
- {
- bottles[i] += diff;
- amountOfWater -= diff;
- }
- }
- if (amountOfWater == 0)
- {
- break;
- }
- }
- List<double> check = bottles.Where(a => a == bottlesCapacity).ToList();
- if (check.Count == bottles.Count)
- {
- Console.WriteLine("Enough water!");
- Console.WriteLine($"Water left: {amountOfWater}l.");
- }
- else
- {
- Console.WriteLine("We need more water!");
- for (int i = bottles.Count-1; i >=0; i--)
- {
- if (bottles[i] != bottlesCapacity)
- {
- index.Add(i);
- bottlesLeft++;
- neededL += bottlesCapacity - bottles[i];
- }
- }
- Console.WriteLine($"Bottles left: {bottlesLeft}");
- Console.WriteLine($"With indexes: {string.Join(", ", index)}");
- Console.WriteLine($"We need {neededL} more liters!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement