C shorthands not working

is there any difference between
a[i][j]+=MAX(a[i][j-1],a[i-1][j]);
and a[i][j]=a[i][j]+MAX(a[i][j-1],a[i-1][j]);
in the problem ‘magic rankings’ if i use the latter one, my solution doesnt work.
my solution to the problem is in the following link
http://www.codechef.com/viewsolution/1675348

a=a+b and a+=b should not be any different. i have no idea why it is different in this case. Please tell me why… thanks in advance

Maybe there is problem in your MAX macro.

This is just a tip, I was told that good practice is to use brackets, try this:

#define MAX(x,y) (x>y?x:y)
1 Like

i would definitely recommend #define max(x,y) ((x)>(y)?(x):(y)) to prevent operator precedence problems.

see Operator Precedence Problems for an example.

1 Like

Thanks that worked…
incredibly foolish of me not to have done that.

You don’t need to award me karma points, you can accept and/or vote for the answer :wink: