t=int(input())
x=0
y=0
while t>0:
a, b = map(int,input().split())
if x<a-b:
x = a-b
elif y<b-a:
y=b-a
if x>y:
leader=1
elif y>x:
leader=2
t=t-1
if x>y:
print(leader," “,x)
elif y>x:
print(leader,” ",y)
What is wrong in this code?? I’m getting wrong answer whenever I submit this whereas I’ve checked this with all the test samples along with many of my own samples
t=int(input())
winner=1;
max=0;
for i in range(t):
a,b=input().split(" ");
diff=int(a)-int(b)
if(abs(diff)>=max):
max=abs(diff);
if(diff>0):
winner=1;
elif(diff<0):
winner=2;
print(winner,max)
what is worng?
what is wrong with this code? It it working fine on ideone and displaying the desired output.
int* getArray(int NOE)
{
return (int*)malloc(sizeof(int)*NOE);
}
int main()
{
int N, Si,Ti;
int i;
cin>>N;
int* A;
A=getArray(N);
for(i=0; i<N; i++)
{
cin>>Si;
//cout<<" ";
cin>>Ti;
A[i]=Si-Ti;
}
int L=abs(A[0]);
int W;
for(i=1; i<N; i++)
{
if(abs(A[i]) > L)
L=A[i];
}
if(L>0)
W=1;
else
W=2;
cout<<W<<" "<<abs(L);
return 0;
}
What’s wrong in my code? It’s working fine locally.Can anyone please explain?
package Beginner;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class The_Lead_Game {
public static void main(String[] args) {
int t,a,b,c,c1;
Scanner sc=new Scanner(System.in);
t=sc.nextInt();
List<Integer> list=new ArrayList<>();
List<Integer> list1=new ArrayList<>();
while(t-->0)
{
a=sc.nextInt();
b=sc.nextInt();
if(a>b)
{
c=a-b;
list.add(c);
}
else
{
c1=b-a;
list1.add(c1);
}
//System.out.println(c);
}
Collections.sort(list, Collections.reverseOrder());
Collections.sort(list1, Collections.reverseOrder());
//Collections.sort(list);
//Collections.sort(list1);
if(list.isEmpty())
{
System.out.println("2");
System.out.println(list1.get(0));
}
else if(list1.isEmpty())
{
System.out.println("1");
System.out.println(list.get(0));
}
else
{
if(list.get(0)>list1.get(0))
{
System.out.println("1");
System.out.println(list.get(0));
}
else if(list1.get(0)>list.get(0))
{
System.out.println("2");
System.out.println(list1.get(0));
}
}
}
}
Once all the rounds are over the player who had the maximum lead at the end of any round in the game is declared the winner.
I think it means any game out of all having highest lead decide the winner right ?
but that is not the case being accepted here.
if other player catches up the lead in 2 or 3 games like Highest lead is say 50 and other person manages lead of 30 in 2 games, he/she is winner.
This is so confusing.
What is the problem with my code?
import java.util.Scanner;
/**
*
-
@author vikaljai
*/
public class Main {
public static void main(String args[]){
int player, maxPlayer=0,diff, maxDiff=0,p1,p2;
Scanner sc = new Scanner(System.in);int loop = sc.nextInt(); while(loop>0){ p1 = sc.nextInt(); p2 = sc.nextInt(); diff = java.lang.Math.abs(p2-p1); if(diff>maxDiff){ maxDiff = diff; maxPlayer = (p1>p2)?1:2; } loop--; } System.out.println(maxPlayer+" "+maxDiff);
}
}
#include<stdio.h>
int main()
{
int x[10000],y[10000], n, i, diff, maxdiffx=0, maxdiffy=0;
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d",&x[i]);
scanf("%d",&y[i]);
}
for(i=0; i<n; i++)
{
diff=0;
if(x[i]>y[i])
{
diff=x[i]-y[i];
if(diff>maxdiffx)
{
maxdiffx=diff;
}
}
else
{
diff=y[i]-x[i];
if(diff>maxdiffy)
{
maxdiffy=diff;
}
}
}
if(maxdiffx>maxdiffy)
printf(“1 %d\n”, maxdiffx);
else
printf(“2 %d\n”, maxdiffy);
return 0;
}
What’s gone wrong with this code?? Runs perfectly in codeshef’s practice IDE but on question’s IDE show wrong answer.
Why is this wrong??
CodeChef: Practical coding for everyone
import java.util.Scanner;
class TLG
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int maxLead=0, leader=0;
for(int i=0;i<n;i++)
{
int p1 = scan.nextInt();
int p2 = scan.nextInt();
if(Math.abs(p1-p2)>maxLead)
{
maxLead = Math.abs(p1-p2);
if(p1>p2) leader=1;
else leader=2;
}
}
System.out.println(leader+" "+maxLead);
scan.close();
}
}
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;
if(n>=1 && n<=10000)
{
int[] s=new int[n];
int[] t=new int[n];
int[] res=new int[n];
for(i=0;i<n;i++)
{
max=sc.nextInt();
min=sc.nextInt();
if(max>=0 && max<=1000)
{ s[i]=max; k++;}
if(min>=0 && min<=1000)
{ t[i]=min; j++;}
res[i]=s[i]-t[i];
}
if(j==n && k==n)
{
max=res[0];
min=res[0];
for(i=1;i<n;i++)
{
if(max<res[i])
max=res[i]; //30x1
}
for(i=1;i<n;i++)
{
if(min>res[i])
min=res[i]; //-60
}
if(max<0)
max=max*(-1); //max=30
if(min<0)
min=min*(-1); //min=60
if(max>min)
System.out.print("1" +" "+ max);
else
System.out.print("2" +" "+ min);
}
}
}
}
i am getting wa(wrong answer)
whats wrong in my code
import java.util.Scanner;
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.
#include <iostream>
using namespace std;
int main()
{
short int t,p1,p2,m1=0,m2=0;
cin >> t;
while(t--)
{
cin >> p1 >> p2;
if(p1>p2 && (p1-p2)>m1)
m1 = p1-p2;
else if(p2>p1 && (p2-p1)>m2)
m2 = p2-p1;
}
if(m1>m2)
cout << 1 << " "<<m1<<endl;
else
cout << 2 << " "<<m2<<endl;
return 0;
}
using namespace std;
int main()
{
int R;
cin>>R;
int P1[R],P2[R],maximum=0,diff=0,W=0;
for(int a=0;a<R;a++)
{
cin>>P1[a]>>P2[a];
if(P1[a]>P2[a])
{
diff=P1[a]-P2[a];
if(diff>maximum)
{
W=1;maximum=diff;
}}
else{diff=P2[a]-P1[a]; if(diff>maximum){W=2;maximum=diff;}
}
}
cout<<W<<" "<<maximum<<endl;
return 0;
}
what is wrong with this code. The answer matched with several test data.
I did that without using any array. what is problem with my code.
#include <iostream>
using namespace std;
int main()
{
int t,p1,p2,m1=0,m2=0;
cin >> t;
while(t--)
{
cin >> p1 >> p2;
if(p1>p2 && (p1-p2)>m1)
m1 = p1-p2;
else if(p2>p1 && (p2-p1)>m2)
m2 = p2-p1;
}
if(m1>m2)
cout << 1 << " "<<m1<<endl;
else
cout << 2 << " "<<m2<<endl;
return 0;
}
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! */
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
{
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);
}
}
}
import java.util.Scanner;
class Players{
public void leaderBoard(int[] p1, int[] p2, int n)
{
int j=1;
for(int i=0; i<n; i++){
p1[i] -= p2[i];
}
int max =p1[0];
for(int i=0; i<n; i++){
// System.out.println("LeaderBoard is: "+p1[i]);
if(max<p1[i])
{
max = p1[i];
j++;
}
}
System.out.println();
System.out.println(j +" "+ max);
}
}
class TheLeadGame {
public static void main(String[] args) //throws IOException
{
Players play = new Players();
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
int p1[] =new int[n];
int[] p2 = new int[n];
// System.out.println("Enter first player score ");
for(int i=0; i<n; i++)
{
p1[i] = sc.nextInt();
}
System.out.println();
// System.out.println("Enter second player score ");
for(int i =0; i<n; i++){
p2[i] = sc.nextInt();
}
play.leaderBoard(p1, p2, n);
}
}
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