< Summary

Information
Class: LeetCode.Algorithms.MaximalScoreAfterApplyingKOperations.MaximalScoreAfterApplyingKOperationsPriorityQueue
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MaximalScoreAfterApplyingKOperations\MaximalScoreAfterApplyingKOperationsPriorityQueue.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 49
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
MaxKelements(...)100%44100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MaximalScoreAfterApplyingKOperations\MaximalScoreAfterApplyingKOperationsPriorityQueue.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Algorithms.MaximalScoreAfterApplyingKOperations;
 13
 14/// <inheritdoc />
 15public class MaximalScoreAfterApplyingKOperationsPriorityQueue : IMaximalScoreAfterApplyingKOperations
 16{
 17    /// <summary>
 18    ///     Time complexity - O(k log n + n log n), where n is the number of elements in the queue and k is the number o
 19    ///     elements
 20    ///     Space complexity - O(n + k), where n is the number of elements in the queue and k is the number of new eleme
 21    /// </summary>
 22    /// <param name="nums"></param>
 23    /// <param name="k"></param>
 24    /// <returns></returns>
 25    public long MaxKelements(int[] nums, int k)
 226    {
 227        var priorityQueue = new PriorityQueue<int, int>();
 28
 2629        foreach (var num in nums)
 1030        {
 1031            priorityQueue.Enqueue(num, -num);
 1032        }
 33
 234        long result = 0;
 35
 2036        for (var i = 0; i < k; i++)
 837        {
 838            var maxElement = priorityQueue.Dequeue();
 39
 840            result += maxElement;
 41
 842            var newElement = (int)Math.Ceiling(maxElement / 3.0);
 43
 844            priorityQueue.Enqueue(newElement, -newElement);
 845        }
 46
 247        return result;
 248    }
 49}