Problem:
Priority Queue

Priority queue is a container of elements which the element with the highest priority should be extracted first.

For $n$ priority queues $Q_i$ ($i = 0, 1, ..., n-1$) of integers, perform a sequence of the following operations.

insert($t$, $x$): Insert $x$ to $Q_t$.

getMax($t$): Report the maximum value in $Q_t$. If $Q_t$ is empty, do nothing.

deleteMax($t$): Delete the maximum element from $Q_t$. If $Q_t$ is empty, do nothing.

In the initial state, all queues are empty.

Input

The input is given in the following format.

$n \; q$
$query_1$
$query_2$
:
$query_q$

Each query $query_i$ is given by

0 $t$ $x$

or

1 $t$

or

2 $t$

where the first digits 0, 1 and 2 represent insert, getMax and deleteMax operations respectively.

Output

For each getMax operation, print an integer in a line.

Constraints

$1 \leq n \leq 1,000$

$1 \leq q \leq 200,000$

$-1,000,000,000 \leq x \leq 1,000,000,000$

Sample Input 1

2 10
0 0 3
0 0 9
0 0 1
1 0
2 0
1 0
0 0 4
1 0
0 1 8
1 1

Sample Output 1

9
3
4
8

Solution in C# (judge verdict: Accepted)

using System.Collections.Generic;
using System;

public class PriorityQueue<T> where T : IComparable
{
    private IComparer<T> _comparer = null;
    private int _type = 0;
    private T[] _heap;
    private int _sz = 0;
    private int _count = 0;
    /// <summary>
    /// Priority Queue with custom comparer
    /// </summary>
    public PriorityQueue(int maxSize, IComparer<T> comparer)
    {
        _heap = new T[maxSize];
        _comparer = comparer;
    }
    /// <summary>
    /// Priority queue
    /// </summary>
    /// <param name="maxSize">max size</param>
    /// <param name="type">0: asc, 1:desc</param>
    public PriorityQueue(int maxSize, int type = 0)
    {
        _heap = new T[maxSize];
        _type = type;
    }
    private int Compare(T x, T y)
    {
        if (_comparer != null) return _comparer.Compare(x, y);
        return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
    }
    public void Push(T x)
    {
        _count++;
        var i = _sz++;
        while (i > 0)
        {
            var p = (i - 1) / 2;
            if (Compare(_heap[p], x) <= 0) break;
            _heap[i] = _heap[p];
            i = p;
        }
        _heap[i] = x;
    }
    public T Pop()
    {
        _count--;
        T ret = _heap[0];
        T x = _heap[--_sz];
        int i = 0;
        while (i * 2 + 1 < _sz)
        {
            int a = i * 2 + 1;
            int b = i * 2 + 2;
            if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b;
            if (Compare(_heap[a], x) >= 0) break;
            _heap[i] = _heap[a];
            i = a;
        }
        _heap[i] = x;
        return ret;
    }
    public int Count() => _count;
    public T Peek() => _heap[0];
    public bool Contains(T x)
    {
        for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true;
        return false;
    }
    public void Clear()
    {
        while (this.Count() > 0) this.Pop();
    }
    public IEnumerator<T> GetEnumerator()
    {
        var ret = new List<T>();
        while (this.Count() > 0) ret.Add(this.Pop());
        foreach (var r in ret)
        {
            this.Push(r);
            yield return r;
        }
    }
    public T[] ToArray()
    {
        T[] array = new T[_sz];
        int i = 0;
        foreach (var r in this) array[i++] = r;
        return array;
    }
}

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var q = int.Parse(line[1]);
        var pq = new PriorityQueue<int>[n];
        for (int i = 0; i < n; i++)
            pq[i] = new PriorityQueue<int>(200000, 1);
        for (int i = 0; i < q; i++)
        {
             line = Console.ReadLine().Trim().Split(' ');
            if (line[0] == "0") pq[int.Parse(line[1])].Push(int.Parse(line[2]));
            else if (line[0] == "1")
            {
                var w = int.Parse(line[1]);
                if (pq[w].Count() > 0) Console.WriteLine(pq[w].Peek());
            }
            else
            {
                var w = int.Parse(line[1]);
                if (pq[w].Count() > 0) pq[w].Pop();
            }
       }
    }
}