P21898 [GeeksforGeeks] Implementation of priority queue using binary heap
普及
题目描述

Given a binary heap implementation of Priority Queue. Extract the maximum element from the queue i.e. remove it from the Queue and return it's value.

Example 1:
Input: 4 2 8 16 24 2 6 5
Output: 24
Priority Queue after extracting maximum: 16 8 6 5 2 2 4
Example 2:
Input: 64 12 8 48 5
Output: 64
Priority Queue after extracting maximum: 48 12 8 5

Your Task:
Complete the function extractMax() which extracts the maximum element, i.e. remove it from the Queue and return it's value.

Expected Time Complexity: O(logN)
Expected Space Complexity: O(N)

Constraints:
1<=N<=500

输入格式

见题面

输出格式

见题面

样例输入
4 2 8 16 24 2 6 5
样例输出
24