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 Sample_Exam_II___June_2016
- {
- class Program
- {
- static void Main(string[] args)
- {
- double totalWater = double.Parse(Console.ReadLine());
- double[] bottles = Console.ReadLine().Split().Select(double.Parse).ToArray();
- double capacity = double.Parse(Console.ReadLine());
- int bottlesLeft = 0;
- double bottleDeficit = 0;
- bool even = true;
- if (totalWater % 2 == 0)
- {
- even = true;
- for (int bottle = 0; bottle < bottles.Length; bottle++)
- {
- double bottleCapacity = bottles[bottle];
- while (bottleCapacity < capacity)
- {
- if (totalWater <= 0)
- {
- bottlesLeft = bottles.Length - bottle;
- bottleDeficit = capacity - bottleCapacity;
- bottle++;
- while (bottle < bottles.Length)
- {
- bottleCapacity = bottles[bottle];
- bottleDeficit += capacity - bottles[bottle];
- bottle++;
- }
- break;
- }
- if (capacity - bottleCapacity >= 1)
- {
- totalWater--;
- bottleCapacity++;
- }
- else
- {
- totalWater -= capacity - bottleCapacity;
- bottleCapacity = capacity;
- }
- }// end of while
- } // end of for
- } //end of if
- else
- {
- even = false;
- for (int bottle = bottles.Length - 1; bottle >= 0; bottle--)
- {
- double bottleCapacity = bottles[bottle];
- while (bottleCapacity < capacity)
- {
- if (totalWater <= 0)
- {
- bottlesLeft = bottle + 1;
- bottleDeficit = capacity - bottleCapacity;
- bottle--;
- while (bottle >= 0)
- {
- bottleCapacity = bottles[bottle];
- bottleDeficit += capacity - bottleCapacity;
- bottle--;
- }
- break;
- }
- if (capacity - bottleCapacity >= 1)
- {
- totalWater--;
- bottleCapacity++;
- }
- else
- {
- totalWater -= capacity - bottleCapacity;
- bottleCapacity = capacity;
- }
- }// end of while
- }//end of for
- }//end of else
- int[] remainingBottlesIndexes = new int[bottlesLeft];
- if (even)
- {
- for (int bottle = bottlesLeft - 1; bottle >= 0; bottle--)
- {
- remainingBottlesIndexes[bottle] = bottles.Length - bottle;
- }
- remainingBottlesIndexes = remainingBottlesIndexes.Reverse().ToArray();
- }
- else
- {
- for (int bottle = 0; bottle < bottlesLeft; bottle++)
- {
- remainingBottlesIndexes[bottle] = bottle;
- }
- remainingBottlesIndexes = remainingBottlesIndexes.Reverse().ToArray();
- }
- if (bottlesLeft == 0)
- {
- Console.WriteLine("Enough water!");
- Console.WriteLine($"Water left: {totalWater}l.");
- }
- else
- {
- Console.WriteLine("We need more water!");
- Console.WriteLine($"Bottles left: {bottlesLeft}");
- Console.WriteLine("With indexes: " + string.Join(", ", remainingBottlesIndexes)); ;
- Console.WriteLine($"We need {bottleDeficit} more liters!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement