kalitarix

Hogswatch

Oct 19th, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Hogswatch
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int numberOfHomes = int.Parse(Console.ReadLine());
  10.             int initialPresents = int.Parse(Console.ReadLine());
  11.  
  12.             int presentsLeft = initialPresents;
  13.             int returns = 0;
  14.             int additionalPresents = 0;
  15.  
  16.             for (int currentHome = 1; currentHome <= numberOfHomes; currentHome++)
  17.             {
  18.                 int numberOfPresents = int.Parse(Console.ReadLine());
  19.  
  20.                 if (presentsLeft >= numberOfPresents)
  21.                 {
  22.                     presentsLeft -= numberOfPresents;
  23.                 }
  24.                 else
  25.                 {
  26.                     returns++;
  27.                     int presentsNeeded = (initialPresents / currentHome) * (numberOfHomes - currentHome) + (numberOfPresents - presentsLeft);
  28.                     additionalPresents += presentsNeeded;
  29.                     presentsLeft += presentsNeeded;
  30.                     presentsLeft -= numberOfPresents;
  31.                 }
  32.             }
  33.  
  34.             if (returns == 0)
  35.             {
  36.                 Console.WriteLine(presentsLeft);
  37.             }
  38.             else
  39.             {
  40.                 Console.WriteLine(returns);
  41.                 Console.WriteLine(additionalPresents);
  42.             }
  43.         }
  44.     }
  45. }
Add Comment
Please, Sign In to add comment