Question: You are given n elements to be inserted into a priority queue. Each element is represented in the format ( x , y ) ,
You are given elements to be inserted into a priority queue. Each element is represented in the format where is the value of the element, and of indicate higher priority. If two elements share the same priority, the elements inserted first will take precedence.
Your task is to write a program to find the sum of the elements that are removed with the highest priority.
Read the input from STDIN and print the output to STDOUT. Do not write arbitrary strings while reading the input or while printing, as these contribut
Constraints:
and should not be negative.
Input Format:
The first line of input contains where denotes the number of elements.
Next lines of input contain where is the element and is its priority.
The last line of input contains where denotes the number of elements to be removed from the queue
Output Format:
The output contains the sum of elements removed from the priority queue.
Sample Input:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
