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 SoftUniWaterSupplies
- {
- class Program
- {
- static void Main(string[] args)
- {
- double water = int.Parse(Console.ReadLine());
- var bottles = Console.ReadLine().Split(' ').Select(double.Parse).ToList();
- double capacity = int.Parse(Console.ReadLine());
- var bottlesLeft = new List<int>();
- double waterNeeded = 0;
- if (water%2 == 0)
- {
- //water is even, start from 0
- for (int i = 0; i < bottles.Count; i++)
- {
- double currentRefill = capacity - bottles[i];
- if (water >= currentRefill)
- {
- water -= currentRefill;
- }
- else
- {
- waterNeeded += currentRefill - water;
- water = 0;
- bottlesLeft.Add(i);
- }
- }
- }
- else
- {
- //water is odd, start from Length
- for (int i = bottles.Count-1; i >= 0; i--)
- {
- double currentRefill = capacity - bottles[i];
- if (water >= currentRefill)
- {
- water -= currentRefill;
- }
- else
- {
- waterNeeded += currentRefill - water;
- water = 0;
- bottlesLeft.Add(i);
- }
- }
- }
- //Print results
- if (waterNeeded == 0)
- {
- //Enough water
- Console.Out.WriteLine("Enough water!");
- Console.Out.WriteLine($"Water left: {water}l.");
- }
- else
- {
- //not enough water
- Console.Out.WriteLine("We need more water!");
- Console.Out.WriteLine($"Bottles left: {bottlesLeft.Count}");
- Console.Out.WriteLine($"With indexes: {string.Join(", ",bottlesLeft)}");
- Console.Out.WriteLine($"We need {waterNeeded} more liters!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement