01. Hogswatch - Retake Exam 2018 August
Здравейте, някой с решение за въпросната задача? Мъча я няколко часа вече.
Условието: https://judge.softuni.bg/Contests/Practice/DownloadResource/3861
Моят код:
<?php
$homes = intval(readline());
$presents = intval(readline());
$timesBack = 0;
$additionalPresents = 0;
$homesVisited = 0;
$remainingHomes = $homes;
$totalAddition = 0;
$presentsLeft = $presents;
for($i = 1; $i <= $homes; $i++) {
$children = intval(readline());
$homesVisited++;
$remainingHomes -= 1;
if($presentsLeft < $children) {
$additionalPresents = $children - $presentsLeft;
$timesBack++;
$totalAddition += intval(($presents / $homesVisited)) * $remainingHomes + $additionalPresents;
$presentsLeft = ( $totalAddition - $additionalPresents );
} else {
$presentsLeft -= $children;
}
}
if($totalAddition <= 0) {
echo $presentsLeft;
} else {
echo $timesBack . PHP_EOL;
echo $totalAddition;
}
?>
В judge минавам с 50/100.