NelIfandieva

ProgrammingFund_27Aug2018_Pr01_Hogswatch

Oct 27th, 2018
46
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Numerics;
  6. namespace Exam_Pr01
  7. {
  8.     class Program
  9.     {
  10.         static void Main()
  11.         {
  12.             int homesToVisit = int.Parse(Console.ReadLine()); // 1 to 100
  13.             int initialPresents = int.Parse(Console.ReadLine());//1 to 10000
  14.             int presents = initialPresents;
  15.             int returnCounter = 0;
  16.             int presentsShort = 0;
  17.             int totalAdditionalPresents = 0;
  18.             int presentsToTake = 0;
  19.             for (int a = 1; a <= homesToVisit; a++)
  20.             {
  21.                 int presentsToLeave = int.Parse(Console.ReadLine());//1 to 100
  22.                
  23.                 if (presents < presentsToLeave)
  24.                 {
  25.                     presentsShort = Math.Abs(presentsToLeave - presents);//see again
  26.                     returnCounter++;
  27.                     //({initialPresents} / {visitedHomes}) * {remainingHomes} + {additionalPresents}
  28.                     presentsToTake = ((initialPresents / a) * (homesToVisit - a)) + presentsShort;
  29.                     presents += presentsToTake;
  30.                     totalAdditionalPresents += presentsToTake;
  31.                 }
  32.                
  33.                 presents -= presentsToLeave;
  34.             }
  35.             if(returnCounter < 1)
  36.             {
  37.                 Console.WriteLine(presents);//read again
  38.             }
  39.             else
  40.             {
  41.                 Console.WriteLine("{0}", returnCounter);
  42.                 Console.WriteLine(totalAdditionalPresents);
  43.             }
  44.         }
  45.     }
  46. }
RAW Paste Data