WindFell

Hogswatch

Aug 28th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2.  
  3. class Hogswatch
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         int homes = int.Parse(Console.ReadLine());
  8.         int initialPresents = int.Parse(Console.ReadLine());
  9.         int presents = initialPresents;
  10.         int homeCommings = 0;
  11.         int additionalPresents = 0;
  12.  
  13.         for (int home = 1; home <= homes; home++)
  14.         {
  15.             int children = int.Parse(Console.ReadLine());
  16.             if (presents >= children)
  17.             {
  18.                 presents -= children;
  19.                 continue;
  20.             }
  21.  
  22.             int presentsShort = children - presents;
  23.             homeCommings++;
  24.             int presentsToTake = initialPresents / (home) * (homes - home) + presentsShort;
  25.             additionalPresents += presentsToTake;
  26.             presents += presentsToTake - children;
  27.         }
  28.  
  29.         if (homeCommings == 0)
  30.         {
  31.             Console.WriteLine(presents);
  32.         }
  33.         else
  34.         {
  35.             Console.WriteLine(homeCommings);
  36.             Console.WriteLine(additionalPresents);
  37.         }
  38.     }
  39. }
Add Comment
Please, Sign In to add comment