What's wrong with my code?? The Lead Game (Wrong Answer)

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{

public static void main (String[] args) throws java.lang.Exception
{
	// your code goes here
	Scanner obj=new Scanner(System.in);
	int n=obj.nextInt();
	int[] s=new int[n];
	int[] t=new int[n];
	int c1=0,c2=0;
	HashMap<Integer,Integer> winner =new HashMap<Integer,Integer>();
    try{
	for(int i=0;i<n;i++){
	    if(i>0){
	        s[i]=s[i-1]+obj.nextInt();
	        t[i]=t[i-1]+obj.nextInt();
	    }
	    else{
	        s[i]=obj.nextInt();
	        t[i]=obj.nextInt();
	    } 
	    if(s[i]>t[i]){
	        if(c1>0){
	            if(winner.get(1)<s[i]-t[i])
	                winner.put(1,s[i]-t[i]);   
	        }
	        else
	            winner.put(1,s[i]-t[i]); 
	        c1++;
	    }
	    else{
	        if(c2>0){
	            if(winner.get(2)<t[i]-s[i])
	                winner.put(2,t[i]-s[i]);
	        }
	        else
	            winner.put(2,t[i]-s[i]);
	        c2++;
	    } 
	}
	if(winner.get(2)>winner.get(1))
	    System.out.println("2 "+winner.get(2));
	else
	    System.out.println("1 "+winner.get(1));
    }
    catch(Exception e){
        return;
    }
}

}

Did you try searching the forum first?

1 Like