Comments

Can you please elaborate on why the max value (for minimum p) will remain preserved across operations?

As per the explanation given for the first testcase — if Bob chooses 35, he gets 5 points for marbles 30,40,50,60,70. Although I agree that problem statement could have been clearer.

I made the same mistake during the contest, actually the score is defined as the number of balls won rather than the sum of the numbers written on them. So for this case it's 3>2 (1 for each ball).

For D1, can someone explain why the answer will be max p?