Advertisement
Guest User

Untitled

a guest
Oct 15th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _2.SoftUni_Water_Supplies
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. double water = double.Parse(Console.ReadLine());
  12. List<double> bottles = Console.ReadLine().Split(' ').Select(double.Parse).ToList();
  13. long capacity = long.Parse(Console.ReadLine());
  14. var indexes = new List<int>();
  15. double initialQuantity = water;
  16. int currentIndex = water % 2 == 0 ? 0 : bottles.Count - 1;
  17.  
  18. while (currentIndex != -1 && currentIndex < bottles.Count)
  19. {
  20. var bottleLiters = bottles[currentIndex];
  21. if (bottles[currentIndex] < capacity)
  22. {
  23. bottles[currentIndex]+= capacity - bottleLiters;
  24. water -= capacity - bottleLiters;
  25. if (water < 0) { indexes.Add(currentIndex); }
  26. }
  27. currentIndex = initialQuantity % 2 == 0 ? ++currentIndex : --currentIndex;
  28. }
  29. if (water >= 0)
  30. {
  31. Console.WriteLine($"Enough water!\nWater left: {water}l.");
  32. }
  33. else
  34. {
  35. Console.WriteLine("We need more water!");
  36. Console.WriteLine($"Bottles left: {indexes.Count}");
  37. Console.WriteLine("With indexes: {0}", string.Join(", ", indexes));
  38. Console.WriteLine($"We need {Math.Abs(water)} more liters!");
  39. }
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement