list($max_yasai, $max_niku, $c, $total) = explode(" ", trim(fgets(STDIN))); $sub_total = 0; for ($yasai=0; $yasai <= $max_yasai; $yasai++) { $niku = $yasai*$c; $sub_total = $yasai + $niku; // 肉が在庫を超えないとき if ($niku <= $max_niku) { if ($sub_total < $total) $today_yasai = $yasai; } } echo $today_yasai."\n";