Intelligent Robots NCR CodeWars 2020

Hii Everyone,

I posted one of the problems I didn’t able to solve during my NCR code wars 2020. Can anyone please help with how to solve this problem. :slightly_smiling_face:

The problem statement is :

You bought N robots. Each robot has some intelligence, for example i th robot has the knowledge p[i]. While you playing with the robot she found a way to transfer the knowledge of the one robot to another.

In this process,you observe that, if X amount of knowledge is transferred from i th to j th ,then K % of knowledge that is transferred is gets dissipated(lost) in the process.

There fore your task is to make the knowledge of all robots equal and maximum.

Constraints:
1<= T <= 50
1<= N <= 100000
1<= k <= 99
0<= p[i] <= 100000, 0<= i < N

Input format
T - test cases
N , K
p1 p2 p3 … pN - array elements

Output:
print the float value of final array element.

sample input :
1
3 50
1 2 3

Sample Output :
1.7500

Explanation :

Robot 3 will transfer its 1.25 intelligence to Robot 1.

           array will look like  [1.625 , 2 , 1.75]

next Robot 2 will transfer its 0.25 intelligence to Robot 1.

          array will lock like [1.75 , 1.75 ,1.75]

Final out put is 1.7500

Its a copied problem from codeforces. You can check its editorial.

Thank you for your reply.
Can you also provide the details of that codeforces problem?.

hey i also got the same problem its verry easy one. I dont know whether it is a codeforces problem , but if u know binary search on real values you can easily solve it , only thing is how you write your check function

Can you provide the link?

can you please elaborate more on this? it will be very @

lets say we want answer as x , compute sum of loss + gain inorder to make every thing to x.

Let this value be val .

if val >0 then we have some extra knowledge left if we make everything to x.
if val<0 then we need some extra knowledge inorder to make everything to x.
if val=0 then x is the answer.

just binary search on x .
so total complexity is O(nlogn).

Same Problem Link : https://codeforces.com/problemset/problem/68/B
You may check its tutorial.