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 n elements to be inserted into a priority queue. Each element is represented in the format (x,y), where x is the value of the element, and y of y 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:
x and y should not be negative.
Input Format:
The first line of input contains N, where N denotes the number of elements.
Next N lines of input contain xy where x is the element and y is its priority.
The last line of input contains K where K 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 Input1:
5
24
53
61
74
94
 You are given n elements to be inserted into a priority

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!