My issue
My code
#include <stdio.h>
int main(void) {
int T;
scanf("%d",&T);
for(int i=0;i<T;i++){
int N,S;
scanf("%d %d",&N,&S);
if(N>=S)
printf("%d\n",S);
else
printf("%d\n",S-N);
}
return 0;
}
Problem Link: CodeChef: Practical coding for everyone
Replace S-N
by 2*N - S
You need to find max difference between T1
and T2
. You are correct in understanding that if sum is less than N then max difference occurs when T1=S
and T2=0
but when S>N
then max difference is when T1=N
and T2=S-N
(because neither T1
nor T2
can be greater than N
)
Therefore, the difference will be T1 - T2 = N - (S-N) = 2N-S