Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

Astroflexx's blog

By Astroflexx, history, 2 years ago, In English

Given an array of integers and an integer m, in one operation, choose atmost m numbers of the array and increment them.

What is the minimum no of operations to make all the elements in the array equal?

1 <= nums[i] <= 1e5

1 <= m <= 1e5

  • Vote: I like it
  • +2
  • Vote: I do not like it

| Write comment?
»
2 years ago, hide # |
← Rev. 4  
Vote: I like it +2 Vote: I do not like it

assuming the numbers are incremented by one i think you can just sort the array and the biggest value minus the smallest would be the answer

why are you people upvoting my wrong solution this solution is wrong i posted the right one in the replies grahhhhh

»
2 years ago, hide # |
← Rev. 4  
Vote: I like it +8 Vote: I do not like it

I think this works.

def solve(nums, m):
    mx = max(nums)
    a = [mx - i for i in nums]
    return max(max(a), (sum(a) + m - 1) // m)