Advertisement
fbinnzhivko

Untitled

Sep 15th, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 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.         decimal totalWater = decimal.Parse(Console.ReadLine());
  9.         decimal[] bottlesArray = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
  10.         decimal bottlesCapacity = decimal.Parse(Console.ReadLine());
  11.  
  12.         decimal consumedWater = 0;
  13.         decimal bottlesFilled = 0;
  14.         decimal bottlesLeft = 0;
  15.  
  16.         decimal allBottles = bottlesArray.Length;
  17.  
  18.         List<decimal> indexes = new List<decimal>();
  19.  
  20.         if (totalWater % 2 == 0)
  21.         {
  22.             for (int i = 0; i < allBottles; i++)
  23.             {
  24.                 consumedWater += bottlesCapacity - bottlesArray[i];
  25.                 if (consumedWater <= totalWater)
  26.                     bottlesFilled++;
  27.                 else
  28.                     indexes.Add(i);
  29.             }
  30.         }
  31.         else
  32.         {
  33.             for (decimal i = allBottles - 1; i >= 0; i--)
  34.             {
  35.                 consumedWater += bottlesCapacity - bottlesArray[(int)i];
  36.                 if (consumedWater <= totalWater)
  37.                     bottlesFilled++;
  38.                 else
  39.                     indexes.Add(i);
  40.             }
  41.         }
  42.         if (consumedWater <= totalWater)
  43.         {
  44.             Console.WriteLine("Enough water!");
  45.             Console.WriteLine("Water left: {0}l.", totalWater - consumedWater);
  46.         }
  47.         if (consumedWater > totalWater)
  48.         {
  49.             Console.WriteLine("We need more water!");
  50.             Console.WriteLine("Bottles left: {0}", allBottles - bottlesFilled);
  51.             Console.WriteLine("With indexes: {0}", string.Join(", ", indexes));
  52.             Console.WriteLine("We need {0} more liters!", consumedWater - totalWater);
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement