MartinGeorgiev

Lift

Jun 16th, 2022 (edited)
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. <?php
  2. $peopleWaiting = intval(readline());
  3. $cabins = explode(' ', readline());
  4. foreach ($cabins as $index => $cabin) {
  5.     if ($cabin < 4) {
  6.         if ($peopleWaiting + (int)$cabin >= 4) {
  7.             $peopleWaiting -= 4 - $cabin;
  8.             $cabins[$index] = 4;
  9.         } else {
  10.             $cabins[$index] = (int)$cabin + $peopleWaiting;
  11.             $peopleWaiting = 0;
  12.         }
  13.     }
  14. }
  15. if (count($cabins) * 4 > array_sum($cabins)) {
  16.     echo "The lift has empty spots!" . PHP_EOL;
  17. } else if ($peopleWaiting > 0) {
  18.     echo "There isn't enough space! $peopleWaiting people in a queue!" . PHP_EOL;
  19. }
  20. echo implode(' ', $cabins);
Add Comment
Please, Sign In to add comment