Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $peopleWaiting = intval(readline());
- $cabins = explode(' ', readline());
- foreach ($cabins as $index => $cabin) {
- if ($cabin < 4) {
- if ($peopleWaiting + (int)$cabin >= 4) {
- $peopleWaiting -= 4 - $cabin;
- $cabins[$index] = 4;
- } else {
- $cabins[$index] = (int)$cabin + $peopleWaiting;
- $peopleWaiting = 0;
- }
- }
- }
- if (count($cabins) * 4 > array_sum($cabins)) {
- echo "The lift has empty spots!" . PHP_EOL;
- } else if ($peopleWaiting > 0) {
- echo "There isn't enough space! $peopleWaiting people in a queue!" . PHP_EOL;
- }
- echo implode(' ', $cabins);
Add Comment
Please, Sign In to add comment