You are viewing a single comment's thread. Return to all comments →
Php
function luckBalance($k, $contests) { $importants = []; $numOfImportant = 0; $sum = 0; foreach ($contests as $contest) { if ($contest[1] === 1) { $importants[] = $contest; $numOfImportant++; } $sum += $contest[0]; } if ($numOfImportant <= $k) { return $sum; } usort($importants, function ($a, $b){ return $a[0] - $b[0]; }); $subTract = 0; $subTractContests = $numOfImportant - $k; for($i = 0; $i < $subTractContests; $i++){ $subTract += $importants[$i][0]; } return $sum - 2 * $subTract; }
Seems like cookies are disabled on this browser, please enable them to open this website
Luck Balance
You are viewing a single comment's thread. Return to all comments →
Php