PROBLEM LINKS
DIFFICULTY
EASY
EXPLANATION
The score starts with 0 and we are given total score after each of Po’s clicks and we need to find the minimum number of users other than Po that could have possibly voted. The important thing to notice is, we just need to maintain the total number of users so far that have voted at least once, and we have the freedom to assign +1 or -1 to each of them :). We can get the total score of users other than Po by just subtracting Po’s vote,
which is just the vote he clicked now. Also, if we can reach a score of S, we can also reach -S ( all votes reversed ). So, we will try to get the score T = abs(S). If we have N users already and to get a total score of T,
1.) T >= N : All N users vote +1, still we need score of (T-N) more, so we need (T-N) more users
2.) T < N : Let some T out of N users vote +1. The remaining (N-T) users should contribute zero, which is possible only if (N-T) is even, else we need just one more user.
SETTER’S SOLUTION
Can be found here.
TESTER’S SOLUTION
Can be found here.