Priority Queue is a container type , which allows you to achieve a constant access speed to the maximum (or minimum) element (O(1)), by increasing the speed of inserting elements into the container to logarithmic (O(logn)).
Basic Operators:
top - Accessing the top
element
size - Returns the number of elements in the container
push - inserts an element and sorts the underlying container
pop - removes the first element
Example of getting the maximum:
#include <iostream>
#include <queue>
#include "stdio.h"
using namespace std;
main()
{
priority_queue <int>p_queue;
int N,a;
scanf("%d",&N);
for(int i = 0;i<N;i++)
{
scanf("%d",&a);
p_queue.push(a);
}
cout<<p_queue.top();
}