Checking Priority Queue Operation

easy
1. Given N integers, your task is to add these elements to the PriorityQueue. 
  2. Also, given M integers, the task is to check if element is present in PriorityQueue. 
  3. If present, print 1 and return the max element of priority queue, and then delete the max element. If not present, print -1.    
  4. Your task is to complete the functions insert(), find(), and delete(), such that it adds, find and delete the elements from the queue respectively.

Input Format

First line contains two integers N(number of elements to be inserted into the Priority Queue) and M. Second line contains N positive integers separated by space. Third line contains M positive integers.

Output Format

Print "1" and max element in newlines if element to be found is present in the PriorityQueue, else print "-1".

Constraints

1 <= N <= 103
  1 <= M <= 103

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
8 5
1 2 3 4 5 2 3 1
1 3 2 9 10
Output
1
5
1
4
1
3
-1
-1
Previous
Remove All Duplicate Nodes In Sorted Linked List
Next
Consecutive Pairs In An Array

Related Questions