fbinnzhivko

Untitled

Jun 10th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         var totalAmountOfWater = int.Parse(Console.ReadLine());
  9.         decimal[] itemsInTheArray = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
  10.         int bottleCapacity = int.Parse(Console.ReadLine());
  11.         var bottlesLeft = 0;
  12.         var indexesOfLeftBottles = new List<int>();
  13.  
  14.         decimal litersFilled = 0;
  15.         if (totalAmountOfWater % 2 == 0)
  16.         {
  17.             for (int i = 0; i < itemsInTheArray.Length; i++)
  18.             {
  19.                 litersFilled += bottleCapacity - itemsInTheArray[i];
  20.                 if (litersFilled > totalAmountOfWater)
  21.                 {
  22.                     bottlesLeft++;
  23.                     indexesOfLeftBottles.Add(i);
  24.                 }
  25.             }
  26.         }
  27.         else
  28.         {
  29.             for (int i = itemsInTheArray.Length - 1; i >= 0; i--)
  30.             {
  31.                 litersFilled += bottleCapacity - itemsInTheArray[i];
  32.                 if (litersFilled > totalAmountOfWater)
  33.                 {
  34.                     bottlesLeft++;
  35.                     indexesOfLeftBottles.Add(i);
  36.                 }
  37.             }
  38.         }
  39.         if (litersFilled > totalAmountOfWater)
  40.         {
  41.             Console.WriteLine("We need more water!");
  42.             Console.WriteLine($"Bottles left: {bottlesLeft}");
  43.             Console.WriteLine($"With indexes: {string.Join(", ", indexesOfLeftBottles)}");
  44.             Console.WriteLine($"We need {litersFilled - totalAmountOfWater} more liters!");
  45.         }
  46.         else
  47.         {
  48.             Console.WriteLine("Enough water!");
  49.             Console.WriteLine($"Water left: {totalAmountOfWater - litersFilled}l.");
  50.         }
  51.     }
  52. }
Add Comment
Please, Sign In to add comment