Guest User

Untitled

a guest
Mar 8th, 2019
151
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $homes = intval(readline());
  4. $inputPresents = intval(readline());
  5.  
  6. $presentsLeft = $inputPresents;
  7. $comeBacks = 0;
  8. $additionalPresents = 0;
  9. $ranOutOfPresents = false;
  10.  
  11. for ($i = 1; $i <= $homes; $i++) {
  12.  
  13.     $input = intval(readline());
  14.  
  15.     //31312
  16.     if ($presentsLeft - $input < 0) {
  17.         $comeBacks++;
  18.         $presentsNeeded = intval(($inputPresents / $i) * ($homes - $i) + ($input - $presentsLeft));
  19.         $additionalPresents += $presentsNeeded;
  20.         $presentsLeft += $presentsNeeded;
  21.         $presentsLeft -= $input;
  22.         $ranOutOfPresents = true;
  23.     } else {
  24.         $presentsLeft -= $input;
  25.     }
  26. }
  27.  
  28. if ($ranOutOfPresents) {
  29.     echo $comeBacks . PHP_EOL;
  30.     echo $additionalPresents . PHP_EOL;
  31. } else {
  32.     echo $presentsLeft;
  33. }
RAW Paste Data