URL
https://leetcode.com/problems/maximal-score-after-applying-k-operations/description/?envType=daily-question&envId=2024-10-14
Code
https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202410/maximal_score_after_applying_k_operations/main.fsx
#r "nuget:FSharpx.Collections"
open System
open FSharpx.Collections
let maxKelements (nums: int list) (k: int) : int64 =
let q =
nums
|> List.map int64
|> List.fold (fun acc n -> PriorityQueue.insert n acc) (PriorityQueue.empty true)
seq { 1..k }
|> Seq.fold
(fun (ret, q) _ ->
let n, q' = PriorityQueue.pop q
let n' = Math.Ceiling(double n / 3.0) |> int64
ret + n, PriorityQueue.insert n' q')
(0L, q)
|> fst