< Back to forum

my code is giving right output but in codechef it is giving wrong ans to the problem THE LEAD GAME ... https://www.codechef.com/viewsolution/17221726


#include<stdio.h>

int main() { int t,w,max,i; scanf("%d",&t);
int a[t],b[t];
for(i=0;i<t;i++)
{
scanf("%d %d",&a[i],&b[i]);

}
if(a[0]>b[0])
   {
       max=a[0]-b[0];
        w=1;
   }
 else
 {
     max=b[0]-a[0];
     w=2;
 }

for(i=0;i<t;i++)
{

if(max<(a[i]-b[i])||max<(b[i]-a[i]))
{
 if(a[i]>b[i])
    {
        max=a[i]-b[i];
        w=1;
    }
 else
    {
     max=b[i]-a[i];
     w=2;
    }

}
}
printf("%d %d",w,max);

return 0;
}
 

Asked by: Manish_Kumar_Savita on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.


Enter your answer details below:


Enter your comment details below:




2 Answer(s)

avatar

The question says that you have to consider the cumulative score after each round to determine the winner. Please read the question statement again carefully. In the above code, you are not calculating the cumulative score after each round.

Siddharth_Garg last updated on April 7, 2019, 6:34 p.m. 0    Reply    Upvote   

avatar

The question wants you to maintain the cumulative lead of a player and wants you to maximise the cumulative lead of any player after any round (not necessarily after the last round).

For example: If the cumulative lead of player A becomes 100 after round 3 and becomes 50 after the last round and the cumulative lead of player B during the course of all rounds never exceeds 100 then only player A wins.

Sourav_Agarwal last updated on April 7, 2019, 6:34 p.m. 0    Reply    Upvote   

Instruction to write good question
  1. 1. Write a title that summarizes the specific problem
  2. 2. Pretend you're talking to a busy colleague
  3. 3. Spelling, grammar and punctuation are important!

Bad: C# Math Confusion
Good: Why does using float instead of int give me different results when all of my inputs are integers?
Bad: [php] session doubt
Good: How can I redirect users to different pages based on session data in PHP?
Bad: android if else problems
Good: Why does str == "value" evaluate to false when str is set to "value"?

Refer to Stack Overflow guide on asking a good question.