# Help needed in DRCHEF (to fix the code, not logic)

ISSUE : I proposed a logic for this question which works fine on paper but i did some blunder in my code because of i m getting wrong answers. I m unable to find mistakes in my code. Kindly help !!!

Can anyone help me figure out why my code is not giving correct output ?

my logic - i have created a multiset storing poppulations of every country in ascending order.

1. At any day (be it the first day of curing) if the number of cures available, X,
is equal or greater than the largest element in multiset (country with the largest population) then the answer will be size of the multiset (as if we start from the last we can cure each country in one day)
2. IF X is less than last element of multiset then arises two cases :

A) if its the first day of curing - then simply use X to cure the country with highest population (last element of set), no need to update X (X remains same for the next day) and then update the countries population (after doubling) on which we used X cures. and we increment the tally of total days required by one.

B) else (when its not first day) - then we further check a condition hence two cases arise -

``````a) we will search for a element in multiset within the range [x,2x] inclusively
if a value found then we will use as many cures as the value of element returned
i.e size of population found within range [x,2x] let that population be P,
thus X = P (updating X for next day) and we remove that element from multiset
(because this country will be country cured on that day) and we increment the
total days required by one.

b) else (when no such value in multiset exits in range [x,2x] ) then again we will
go to cure the country with largest population present. X will be updated to 2*X
(because today we can use 2*X cures to cure the most populated country), thus
X = X*2, we also update the population of that country after doubling at end of
the day.
``````

Note : Also before doing all these tasks i also check whether my multiset is empty or not.

I have also attached explanation with sample test-cases.

Testcase 1 :
when X = 1, N =5 and country’s populations are 10, 20, 30, 40, 50

Testcase 2 :
when X = 10, N = 3 and country’s populations are 1, 20, 110

PLZ read this and help me out with my logic (which works on paper but i m failing to write as a whole code) and piece of code .

dont you think in second test case you should have cured country with population 1 first, as ability to cure is not going to go lower than X.

uhh I think no, although we have cured one country completely by using 1 cure on Day 1, but next day we can use only 2 vaccines at max, then on 3rd day 4 vaccines, then on 4th 8 vaccines and on 5th day you can use at most 16 vaccines. so we can conclude that by end of 5th day we cannot cure country with population 110.

btw i m looking to correct my code according to given logic. currently i don’t care much about my logic !