Bugs

0

0 votes
Binary search algorithm, Medium, Fenwick Tree, Searching, Hiring, Algorithms, Binary Search, Searching algorithm
Problem

You are a developer in a company. You call the bugs in your code as enemies. You maintain an array A of the list of enemies in decreasing order of their difficulty which implies the most difficult bug will be the first element of the array. Initially, there are no bugs in the code. You are given N tasks. Each task contains one of the following two types of operations:

  1. 1 P: Add a bug with difficulty P into array A
  2. 2: Sort the array in decreasing order and print the difficulty of (n/3)th bug in the sorted array, where n is the size of the array A. If the number of bugs is less than 3, print Not enough enemies.

Input format

  • First line: An integer N denoting the number of tasks
  • Next N lines: One of the two types of operations

Output format

For every operation of type 2, print the difficulty of (n/3)th bug in the sorted array, where n is the size of the array A. If the number of bugs is less than 3, print Not enough enemies.

Constraints

1N5105

1P109

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Task 1: Add 1 to the array. Current array is [1].

Task 2: Add 7 to the array. Current array is [7,1].

Task 3: Array size is less than 3. Output is "Not enough enemies".

Task 4: Add 9 to the array. Current array is [9,7,1].

Task 5: Add 21 to the array. Current array is [21,9,7,1].

Task 6: Add 8 to the array. Current array is [21,9,8,7,1].

Task 7: Add 5 to the array. Current array is [21,9,8,7,5,1].

Task 8: Array size is 6. n/3 is equal to 2. Number at rank 2 in array is 9. Output is 9.

Task 9: Add 9 to the array. Current array is [21,9,9,8,7,5,1].

Task 10: Array size is 7. n/3 is equal to 2. Number at rank 2 in array is 9. Output is 9.

Editor Image

?