Need Help! my code is successfully executed in Code,Compile & Run Panel of Codechef but on submission shows Wrong answer. The Question Code is TLG(The Lead Game) of Begineer level.And, my code is:








 #include <iostream>
using namespace std;

int main() {
               // your code goes here
               int max1=0,max2=0;
               long n;
               cin>>n;
               if(n>=1 && n<=10000)
               {
	                 for(int i=0;i<n;i++)
	                {
	                      int si,ti,temp1,temp2;
	                     cin>>si>>ti;
	                     if((si>=1 && si<=1000) && (ti>=1 && ti<=1000))
    	                {
    	                    if(si>ti)
    	                        temp1=si-ti;
    	                   else if(ti>si)
    	                        temp2=ti-si;
    	      
    	                }
 
   	    if(temp1>temp2)
    	    {
    	    	if(temp1>max1)
					 max1=temp1;	
			}
    	       
    	   else
    		{
    			if(temp2>max2)
    				 max2=temp2;
			}
    	 
	   }
	   if(max1>max2)
	        cout<<1<<" "<<max1;
	   else(max2>max1)
	        cout<<2<<" "<<max2;
	
	}
	return 0;
}

Please Format your code and also provide a link to the question in the description. :slightly_smiling_face:

Edit:
I guess you’re talking about this solution. There are a couple of problems in your code.
You don’t need if statements to validate the constraints. They are always true.
I suppose you didn’t look the word cumulative in the problem statement. Try to go through the example given in the statement to understand.
If you don’t initialize your variables, they will be filled with some garbage values.
Link to corrected submission. Notice the changes.

2 Likes

Thank you so much sir for going through my code and sorry for posting unformat code and not providing the link. I will keep it my from next time.

Your code was really helpful :blush:
Thanks again sir.

2 Likes