values and two integers, reach and moves.
You must make exactly moves moves. In one move you pick an element that has not been touched yet and add to it any integer from -reach to reach inclusive (0 is allowed). Each element changes at most once.
Return the largest number of equal elements the array can hold after all the moves.values=[2, 9, 6, 12], reach=3, moves=2 → 3
Move 6 by +3 and 12 by −3: the array becomes [2, 9, 9, 9] with three 9s.
values=[5, 5, 20], reach=4, moves=1 → 2
20 is out of reach from the 5s (that takes 15, the limit is 4), so the best is the two 5s already there.
values=[1, 3, 5, 7], reach=2, moves=4 → 3
values=[2, 9, 6, 12], reach=3, moves=2
3
Run checks the first 3 tests in your browser. Submit checks all 68 tests on the server, hidden ones included.