** **PREREQUISITES** :**

Priority Queue or Queue

**PROBLEM**:

Pied Piper currently have A users and gains X user every day, Other company Hooli has B users and gains Y users every day, given a parameter Z you have to tell which company reaches Z users first. In case if both the company reach Z users on the same day then you have to print “RIP”

Piper has N supporters C_{1}, C_{2},…C_{n}. When an i-th supporter supports Piper, company instantly gains C_{i} subscriber and the value of C_{i} is halved

A supporter can support any number of times. Print the “minimum” number of time supporters must support so that Pied piper gains control of Pipernet else print “RIP”.

**APPROACH**

First we need to calculate the new value of A that is before any support, it can be easily done using:

val = (Z - B) // Y

“val” above represents the day after which “hooli” reaches Z users.

Now we calculate the users gained by Pied Piper in that same number of days using:

newA = A + X * val

After above calculation we need to find if it is possible for Pied Piper to reach Z users with the help of support if so then print the minimum number else “RIP”

The problem can be easily solved using a priority queue, in priority using heap-pop we can pop out the smallest element of the heap, so to actually put this property in use we first replace all the elements of the array by their negative value and heapify it. After this whenever we heap-pop we will get the "biggest number in array or the smallest in heap "(think about this). just keep adding the support(max C_{i}) value to new value of A, if it gets greater than z then break, After adding the value of max(arr) to new value of A check

if int(C

_{i}/2) >=0

if it is greater then zero then append floor(C_{i}/2 ) to heap. If length of heap gets equal to zero then break.

Check if newA > Z: print(count), else print “RIP”

Solution (python3) - above approach

Solution using Alternative approach - using 2 queues