0){ $cost[$i] = pay($cost[$i]); } } if ($have[1] < 0){ echo "No\n"; } else { echo "Yes\n"; } function pay($cost) { if ($have[3] > 0 && $have[2]*5000 + $have[1]*1000 < $cost){ $have[3]--; $cost -= 10000; } else if ($have[2] > 0 && $have[1]*1000 < $cost){ $have[2]--; $cost -= 5000; } else { $have[1]--; $cost -= 1000; } return $cost; } ?>