my code is working exactly fine with test cases and all other possible inputs but as soon as i hit the submit button it shows wrong answer.
here is the source code.
include
int main ()
{
int n,i,diff,win;
scanf("%d",&n);
int max[n],winer[n],s[n],t[n];
for(i=0;i<n;i++)
{
scanf("%d%d",&s[i],&t[i]);
if(s[i]-t[i]>0)
{
max[i]=s[i]-t[i];
winer[i]=1;
rounds=input()
p1_score=[]
p2_score=[]
difference_array=[]
for i in xrange(0,rounds):
a, b = map(int, raw_input().split())
p1_score.append(a)
p2_score.append(b)
for t in range(0,rounds):
difference=p1_score[t]-p2_score[t]
difference_array.append(difference)
difference_array.sort()
x1=abs(difference_array[0])
x2=abs(difference_array[rounds-1])
if x1>x2:
print “2”, x1
elif x2>x1:
print “1”, x2
else:
pass
This is the code I wrote in Python 2.7. Please tell me what’s wrong with this. Test case works fine with it.
#include <stdio.h> #include <stdlib.h> #define PLAYER1 1 #define PLAYER2 2
//this program is to count scores of two in a game for N round and declaring winner.
int main()
{
int n,si,ti;
int L1=0,L2=0;
scanf("%d",&n);
while(n–){
scanf("%d %d",&si,&ti);
if( (si-ti) > L1 ? (L1=si-ti):0){
}
else if ((ti-si)>L2 ? (L2=ti-si) : 0);
}
if(L1>L2) printf("%d %d",PLAYER1,L1);
else printf("%d %d",PLAYER2,L2);
return 0;
}
This seems wrong to me since lead in one round is independent of other/previous rounds. MEaning, if 1 had lead of 50 in round one, and next round scores are Player1- 250, player2 -260 then elad of 2 will be 10. But your statement will do lead = 50(lead) -10 (p1-p2)
Greetings!
May I ask for an optimal test case for this problem?
all the test cases that I use are confirmed but I am still getting wrong answer on submission
and I need to check if I am doing wrong and where.
Best Regards.
Robert.
Hi, the problem with your code is that it only gives the output result of the last scores input in it. You need to give the result from all of the rounds’ scores input.
Code Works fine. why codechef showing Wrong Answer??
import java.util.;
import java.io.;
class lead{
public static void main(String args[]){
Scanner t = new Scanner(System.in);
int n = t.nextInt();//no. of rounds
int i, winner=0, max;
int a[] =new int[n];
int b[] =new int[n];
int c[] = new int[n];
for(i=0;i<n;i++){
a[i] = t.nextInt();
b[i] = t.nextInt();
}