This is a verified interview question from Flipkart. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Priority Queue Removal Sum - Flipkart Online Assessment SDE Role IIIT Bhubaneswar" covers key patterns like Arrays.
"You are given **N** elements to be inserted into a priority queue. Each element is represented as a pair **(x, y)**, where: * **x** is the value of the element. * **y** is its priority. A higher value of **y** indicates a higher priority. If two elements have the same priority, the element inserted **earlier** is removed first (FIFO order for equal priorities). Your task is to find the **sum of the first K elements removed** from the priority queue. --- ### Input Format * The first line contains an integer **N**, the number of elements. * The next **N** lines each contain two integers: * **x** — value of the element. * **y** — priority of the element. * The last line contains an integer **K**, the number of elements to remove from the priority queue. --- ### Output Format Print a single integer representing the **sum of the values** of the first **K** elements removed from the priority queue. --- ### Constraints * (x >= 0) * (y >= 0) --- ### Sample Input 1 ``` 4 3 1 7 3 4 2 5 3 2 ``` ### Sample Output 1 ``` 12 ``` --- ### Explanation The elements are removed in decreasing order of priority. Insertion order: ``` (3,1) (7,3) (4,2) (5,3) ``` Removal order: ``` (7,3) (5,3) // Same priority as 7, but inserted later, so removed after 7 (4,2) (3,1) ``` The first `K = 2` removed elements have values `7` and `5`. Sum = `7 + 5 = 12`."
Join thousands of developers practicing for Flipkart.