import java.util.Scanner;
class Tlg
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i,max,min,j=0,k=0;
public class TheLeadGame
{
public static void main(String[] Sym)
{
Scanner sym = new Scanner(System.in);
int round = sym.nextInt();
int[] intarrr = new int[]{0,0};
for (int i = 0; i < round; i++)
{
int a = sym.nextInt();
int b = sym.nextInt();
int absVal = Math.abs(a-b);
if(intarrr[1] < absVal)
{
intarrr[1] = absVal ;
intarrr[0] = (a > b) ? 1 : 2;
}
}
System.out.println(intarrr[0] + " " + intarrr[1]);
sym.close();
}
I don’t think there is need of creating 4 arrays. I solved this answer using 4 variables only. Codechef shows wrong answer when I submit my code but when I run the code on my computer the answer that I get always correct. Below is the code that I wrote.
what is wrong with my code. whenever i am submitting it , its showing wrong answer , but i have tried many test cases and all working fine . please reply . thanku…
/* package codechef; // don’t place package name! */
/* 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
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int player1[] = new int[n];
int player2[] = new int[n];
int rem1 = 0;
int rem2 = 0;
for (int i = 0; i < n; i++) {
player1[i] = sc.nextInt();
player2[i] = sc.nextInt();
}
for (int i = 0; i < n; i++) {
if (player1[i] >= player2[i]) {
int sub1 = player1[i] - player2[i];
if (sub1 > rem1)
rem1 = sub1;
} else{
int sub2 = player2[i] - player1[i];
if (sub2 > rem2)
rem2 = sub2;
}
}
if (rem1 > rem2)
{
int w =1;
System.out.println(w+" "+ rem1);
}
else
{
int w =2;
System.out.println(w+" "+rem2);
}
}
n=int(input())
lead=[]
for i in range(n):
score=[int(x) for x in input().split()]
lead.append(score[0]-score[1])
if((n==1)):
if(score[0]>score[1]):
print(1,score[0]-score[1])
if(score[0]<score[1]):
print(2,score[1]-score[0])
player1=abs(max(lead))
player2=abs(min(lead))
if(player1>player2):
print(1,player1)
elif(player1<player2):
print(2,player2)
public static void main(String[] args){
int a,b,t,pA=0,pB=0,currentLeadingPlayer=0,currentlead=0;
int winningLead=0,winningPlayer=0;
Scanner scanner = new Scanner(System.in);
t =scanner.nextInt();
while (t-->0){
a=scanner.nextInt();
b=scanner.nextInt();
pA +=a;//adding previous score of a
pB +=b;//adding previous score of b
// If confused why am i doing this look in comment section
if (pA>pB){
currentLeadingPlayer =1;
currentlead = pA-pB;
}else {
currentLeadingPlayer =2;
currentlead = pB-pA;
}
if (winningLead<currentlead){
winningLead = currentlead;
winningPlayer = currentLeadingPlayer;
}
}
System.out.println(winningPlayer+" "+winningLead);
}
}
/*
Go Look in problem Statement again the second table shows us that for every player the score is added from previous score
and then the lead is calculated on those updated scores
Based on lead which player is selected
*/
nf = input()
ni = int(nf)
if ni >= 1 and ni <= 10000 :
lead = []
lead1 = []
R = []
even = []
for x in range(1,ni+1):
splitted = input().split()
for y in splitted :
if (0 > int(y) or int(y) > 1000 ):
exit()
else :
R.append(int(y))
n = 0
while n < 2*int(nf):
even.append(n)
n = n + 2
n = ni
for y in even :
if R[y] > R[y+1]:
L = R[y] - R[y+1]
lead.append(L)
lead1.append(1)
else:
L = R[y+1] - R[y]
lead.append(L)
lead1.append(2)
maxi = max(lead)
z = lead.index(maxi)
m = lead1[z]
print(m,maxi)
nf = input()
ni = int(nf)
if ni >= 1 and ni <= 10000 :
lead = []
lead1 = []
R = []
even = []
for x in range(1,ni+1):
splitted = input().split()
for y in splitted :
if (0 > int(y) or int(y) > 1000 ):
exit()
else :
R.append(int(y))
n = 0
while n < 2*int(nf):
even.append(n)
n = n + 2
n = ni
for y in even :
if R[y] > R[y+1]:
L = R[y] - R[y+1]
lead.append(L)
lead1.append(1)
else:
L = R[y+1] - R[y]
lead.append(L)
lead1.append(2)
maxi = max(lead)
z = lead.index(maxi)
m = lead1[z]
print(m,maxi)
Can somebody help me with this code. It is giving correct answer with the given values in the question.But after submitting it shows wrong answer. Any help will be appreciated. Thank you
I checked for sample input given in the problem. Tried couple of examples myself and it works fine. Can you please point out what is wrong here which prevents my answer form getting accepted.
The question is a bit unclear. Actually your solution is calculating lead, in each round. But the correct solution requires you to calculate the cumulative lead after each round.