Find The Highest Profit

https://algo.monster/problems/find_the_highest_profit

PHP Solution:

function maximumProfit($inventory, $order)
{
$N = count($inventory);
$max_heap = [];
$maxProfit = 0;

for ($i = 0; $i < $N; $i++) {
array_push($max_heap, $inventory[$i]);
asort($max_heap);
$max_heap = array_reverse($max_heap);
}

while ($order > 0) {
$order–;

$X = $max_heap[0];
array_shift($max_heap);

$maxProfit += $X;

array_push($max_heap, ($X - 1));
asort($max_heap);
$max_heap = array_reverse($max_heap);

}

return $maxProfit;
}

echo maximumProfit([3, 5], 6);

Very nice sollution …thank you very much