CWOD last question , Help needed

Given an array and an integer K , you can perform the following procedure atmost K time on the array
Either subtract 1 or add 1 to an element of the array
Find minimum difference between maximum value and minimum value.
1<=N<=10^5
1<=K<=10^9
1<=arr [ i ] <=10^9

1 Like

Can you provide link of question ?

2 Likes

For getting response from the people provide the link of the question and also what you are not able to understand otherwise people will just give you solution with some explanation

No , he cant because the question is no longer visible.

1 Like

It looks like he needs the solution

1 Like

I was also unable to solve the problem , and am wondering how so many people solved it , and not only that I saw a solution after the contest which somene was claiming to pass , and he has just brute forced in it ( which was surely wrong solution ). @aneee004 @ssrivastava990 @ssjgz @cubefreak777 can you guys suggest a solution . Do remember the value of K.

1 Like

it is atmost K times , a typo is there :slight_smile:

1 Like

Thanks it is now updated

1 Like

You didn’t took care of the condition when max and min might change after adding k to minimum value of substracting k from end value.

1 Like

Oh i got it .

Can you tell me plz
why questions link is not available ?

Actually It is a problem of Crio Winter of Doing , and I don’t know why they just made the problems hidden after some time of the contest , so that is why it is not visible anymore

For those who are looking for solution. This is a codeforces problem - Minimizing Difference. This can be solved using binary search with some observation.

I was having the same feel that I had seen it somewhere but then I thought , may be I saw one which could be solved in O(K). Thanks Man I appreciate it.

1 Like