You are not logged in. Please login at www.codechef.com to post your questions!

×

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

 0 #include #include 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;imax) max = L[i]; winner = R[i]; } printf("%d %d",winner,max); return 0; }  asked 20 May '15, 12:56 13●2 accept rate: 0%

 0 http://www.codechef.com/viewsolution/6764394 TAKE A LOOK AT MY SOLUTION answered 20 May '15, 13:01 469●5●29 accept rate: 7% So, where is the fault of my code ??? I don't see any of it. Just a different way to solve the problem (21 May '15, 08:31) (22 May '15, 12:43)
 0 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;imax) 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. answered 21 May '15, 11:37 16●1 accept rate: 50%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×3,766
×2,718
×1,388
×1,070
×847
×56

question asked: 20 May '15, 12:56

question was seen: 941 times

last updated: 22 May '15, 12:43