public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
int player=0,max;
int almax=0,playerf=0;
while(t-->0){
int count=0;
int a = scan.nextInt();
int b = scan.nextInt();
if(a>b){
max=a-b;
player=1;
}
else{
max=b-a;
player=2;
}
//finding maximum
if(max>=almax){
almax=max;
playerf=player;
}
}
System.out.println(playerf+" "+almax);
}
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
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.
@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);
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);
}
}