Why I'm getting WA with this code on The Lead Game problem ????

#include <stdio.h>
#include <math.h>
int main(void) {
int n,i=0,max,winner;
scanf("%d",&n);
int S[n],T[n],R[n],L[n];
while(n–){
scanf("%d",&S[i]); scanf("%d",&T[i]);
L[i] = abs(S[i]-T[i]);
if (S[i]>T[i])
R[i]=1;
else
R[i]=2;
i++;
}
max = L[0];
winner = R[0];
for (i=1;i<n;++i){
if (L[i]>max)
max = L[i];
winner = R[i];
}
printf("%d %d",winner,max);
return 0;
}

CodeChef: Practical coding for everyone TAKE A LOOK AT MY SOLUTION

OK I need the karma.
Here is an accepted version of your code,
http://www.codechef.com/viewsolution/6988064

There are three primary errors which I will point out.

int S[n],T[n]

You don’t need to store the values why use array.

Simply replace this with

int S,T;

scanf(“%d”,&S[i]); scanf(“%d”,&T[i]);

The scores are cumulative, read the question again. Score of the previous round questions get carried forward.
Replace this with,

int a,b;

    scanf("%d",&a); scanf("%d",&b);

    S=S+a;

    T=T+b;




**while(n--)**

You are reducing the value of n here to 0, how do you expect the next for loop to work,

for (i=1;i<n;++i)

**if (L[i]>max)

    max = L[i];

    winner = R[i];

**

You missed a bracket here. Without it winner is always getting set to the R[n-1]

**if (L[i]>max){

    max = L[i];

    winner = R[i];

}**

Hope this helps.

So, where is the fault of my code ??? I don’t see any of it. Just a different way to solve the problem

Refer to this: http://discuss.codechef.com/questions/68537/lead-game-can-someone-give-other-test-cases-so-i-can-find-out-whats-wrong?page=1#68540