TLG - Editorial

What is wrong in this?
It is working fine in eclipse, but codechef editor shows the wrong answer.

function myFunc(arr1,arr2) {
for (let i = 0; i < 3; i++) {
let lead = [];
if (arr1[i] > arr2[i]) {
if (lead<(arr1[i] - arr2[i])) {
lead = arr1[i] - arr2[i];
return (lead + " P1 has lead");
}
}
else{
if (arr1[i] < arr2[i]) {
if (lead < (arr2[i] - arr1[i])) {
lead = arr2[i] - arr1[i];
return (lead + " P1 has lead");
}
}
}
}
return lead;

}
console.log(myFunc([8,9,6],[8,5,8]));

//–Whats Wrong with my Code–//
//–trying to run on console in JS–//

Hey,here is my code, it is showing correct output in my laptop for all inputs but here it is showing wrong answer. can someone tell me why ?

n=int(input())
list1=[]
list2=[]
list3=[]
list4=[]
for i in range(n):
(a,b)=list(map(int,input().split()))
list1.append(a)
list2.append(b)
a=abs(a)
b=abs(b)
if(a>b):
c=(a-b)
d=1
list3.append©
list4.append(d)
else:
c=b-a
d=2
list3.append©
list4.append(d)
position=list3.index(max(list3))
print(list4[position],max(list3))

what is wrong with my code?
#include
#include
#include
using namespace std;
int main()
{
int n;
cin>>n;

    int p1[n],p2[n],lead[n],i,large1=0,largest,w;
    double mlead[n];
    for(i=0;i<n;i++)
    {
        //cout<<"p1"<<endl;
        cin>>p1[i];
        //cout<<"p2"<<endl;
        cin>>p2[i];
        lead[i]=p1[i]-p2[i];
        mlead[i]=abs(lead[i]);



    }
        largest=mlead[0];
        for(i=1;i<n;i++)
        {
            if(largest<mlead[i])
               {

                largest=mlead[i];
                large1=i;
               }
        }
        //cout<<largest<<endl;

        //cout<<lead[large1];
    if(lead[large1]>0)
    {
        w=1;
        cout<<w<<" "<<largest;
    }
    else
    {
        w=2;
        cout<<w<<" "<<largest;
    }



return 0;

}

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)

what is wrong with my code

#include
#include
#include

using namespace std;

int main()
{
int n;
cin>>n;
int p1[n],p2[n],lead[n],mlead[n],temp1=0,temp2=0;
for(int i=0;i<n;i++)
{
cin>>p1[i]>>p2[i];
}
for(int i=0;i<n;i++)
{
temp1=temp1+p1[i];
temp2=temp2+p2[i];
lead[i]=temp1-temp2;
}
for(int i=0;i<n;i++)
{
mlead[i]=abs(lead[i]);
}
sort(lead,lead+n);
sort(mlead,mlead+n);
if(lead[n-1]>0)
cout<<1<<" “<<mlead[n-1];
else if(lead[n-1]<0)
cout<<2<<” "<<mlead[n-1];

return 0;

}

import java.util.Scanner;

class LeadGame {

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
*/

Support with a upvote if it helped

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)

What is wrong with the following code ?

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)

rounds = int(input())
pOne = []
pTwo = []

for i in range(0, rounds):
(a, b) = input().split()
lead = int(a) - int(b)
if lead>0 :
pOne.append(lead)
else :
pTwo.append(lead)

mOne = max(pOne)
mTwo = max(pTwo)

if mOne>mTwo :
print("{1} {0}".format(mOne,1), end=’ ‘)
else :
print("{1} {0}".format(mTwo,2), end=’ ')

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

Please reply me that what is wrong in my code. it is poping wrong answer.
Code:
#include <bits/stdc++.h>

using namespace std;

int main()
{ int n,i,a[20000],b[20000],c[20000],x=0,m=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i]>>b[i];
c[i]=a[i]-b[i];
}
x = c[0],m = c[0];
for (i = 1; i < n; i++)
{if (c[i] > x)
x = c[i];
}
{if (c[i] < x)
m = c[i];
}
int j=abs(x);int k=abs(m);
if(j>k)
{cout<<“1”<<"\t"<<j;}
else
{cout<<“2”<<"\t"<<k;}

}