Problem: Takahashi is going to buy N items one by one.  The price of the i-th item he buys is A_i yen (the currency of Japan).  He has M discount tickets, and he can use any number of them when buying an item.  If Y tickets are used when buying an item priced X yen, he can get the item for \frac{X}{2^Y} (rounded down to the nearest integer) yen.  What is the minimum amount of money required to buy all the items?

Submission attempts (in order):
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NM = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, M) = (NM[0], NM[1]);
        var A = ReadLine().Split(' ').Select(s => int.Parse(s)).OrderByDescending(x => x).ToArray();

        var priorityQueue = new PriorityQueue<int>();

        foreach (var a in A)
            priorityQueue.Push(a);

        for (int i = 0; i < M; i++)
        {
          int nip = priorityQueue.Pop()/2;
          priorityQueue.Push(nip);
          
        }

        var ans = priorityQueue.Sum(x => (long)x);

        WriteLine(ans);

    }
}
public class PriorityQueue<T> : IEnumerable<T>
    where T : IComparable<T>
{
    private List<T> buffer;
    public int Count { get => buffer.Count; }
    public bool IsDescending { get; }
    private int Compare(T a, T b) => IsDescending ? a.CompareTo(b) : b.CompareTo(a);

    public PriorityQueue(bool isDescending = true)
    {
        buffer = new List<T>();
        IsDescending = isDescending;
    }

    public void Push(T item)
    {
        buffer.Add(item);

        var root = 0;
        var child = buffer.Count - 1;

        while (root < child)
        {
            var parent = (child - 1) / 2;

            if (Compare(buffer[parent], buffer[child]) < 0)
                (buffer[parent], buffer[child]) = (buffer[child], buffer[parent]);

            child = parent;
        }
    }

    public T Pop()
    {
        var item = buffer[0];
        buffer[0] = buffer[^1];
        buffer.RemoveAt(buffer.Count - 1);

        var root = 0;
        var parent = root;
        var child = 1;

        while(child < buffer.Count)
        {
            if (child < buffer.Count - 1)
            {
                var leftChild = child;
                var rightChild = child + 1;

                if (Compare(buffer[leftChild], buffer[rightChild]) < 0)
                    child = rightChild;
            }

            if (Compare(buffer[parent], buffer[child]) < 0)
                (buffer[parent], buffer[child]) = (buffer[child], buffer[parent]);

            parent = child;
            child = 2 * parent + 1;
        }

        return item;
    }

    public IEnumerator<T> GetEnumerator()
    {
        return buffer.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return this.GetEnumerator();
    }
}


n,m=map(int,input().split())
a=list(map(int,input().split()))

for i in range(m):
  a.sort()
  t=int(a[-1]/2)
  a.append(t)
print(sum(a))

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
d=[]
for i in range(m):
  if len(a)>0:
    if len(d)==0:
      d.append(a[0]//2)
      a.pop(0)
    else:
      if a[0]>=d[0]:
        d.append(a[0]//2)
        a.pop(0)
      else:
        d.append(d[0]//2)
        d.pop(0)
  else:
    if len(a)==0:
      a.append(d[0]//2)
      d.pop(0)
    else:
      if d[0]>=a[0]:
        a.append(d[0]//2)
        d.pop(0)
      else:
        a.append(d[0]//2)
        a.pop(0)
print(sum(d)+sum(a))

Verdicts: Runtime Error

Wrong Answer

Accepted