I solved this problem(https://www.codechef.com/problems/SORTSUB7EZ) by using the assumption that:- "all the remainders of ai(wrt any integer) belong to set {0, 1, 2, ....,(ai+1)/2-1}" but idk the proof, can anyone help?
PS: i tried a few values of ai and found out that assumption.









Auto comment: topic has been updated by divya8080 (previous revision, new revision, compare).
to get remainder $$$x \ (2 * x \lt a)$$$ you can do always do $$$a_i mod (a_i - x)$$$ as
$$$y = a_i - x$$$
$$$2y = 2a_i - 2x$$$
$$$a_i + (a_i - 2x) \gt a$$$
$$$2y \gt a$$$
thanks gotcha!!
Hi Divya,
Lets say
xis the number andx % d = rem. So this meansx = q*d + remwherer < dand hence max value of r can bemin(d - 1, x - d).When will r has it max value? When
d - 1 = x - d. So2d - 1 = xand henced = (x + 1) / 2. So when we taked - 1to be r we getr = (x + 1) / 2 - 1. Hope this helps!