int main()
{
int totalRounds, lead, maxLead1 = 0, maxLead2 = 0;
cin >> totalRounds;
int **stats = new int*[totalRounds];
for (int i = 0; i < totalRounds; i++)
stats[i] = new int[totalRounds];
for (int i = 0; i < totalRounds; i++)
cin >> stats[0][i] >> stats[1][i];
for (int i = 0; i < totalRounds; i++)
{
if (stats[0][i] > stats[1][i])
{
lead = stats[0][i] - stats[1][i];
if (lead > maxLead1)
maxLead1 = lead;
}
else
{
lead = stats[1][i] - stats[0][i];
if (lead > maxLead2)
maxLead2 = lead;
}
}
if (maxLead1 >= maxLead2)
cout << "1 " << maxLead1;
else
cout << "2 " << maxLead2;
for (int i = 0; i < totalRounds; i++)
delete[] stats[i];
delete[] stats;
return 0;
}
I use a 2d array to store the data of the score of the two players as below:
[0][i] (1st Player) [1][i] (2nd Player)
[0][0] [1][0] <-- 1st Round
[0][1] [1][1] <-- 2nd Round
… … <-- … Round
[0][i - 1] [1][i - 1] <-- ith Round
My Code is working absolutely fine with all the test cases and other custom inputs also but the moment i hit submit,it shows wrong answer.Can anyone help figure out the problem. Heres myn code. CodeChef: Practical coding for everyone
I have written program in python and its showing NZEC.
The Lead Game:
i = 0
score_dif= 0
p1_score,p2_score = 0,0
while True:
rounds = int(raw_input())
if rounds <= 10000:break
else : continue
while i < rounds :
p1_score,p2_score = map(int, raw_input().split())
if (1 <= p1_score <= 1000) and (1 <= p2_score <= 1000) and (p1_score != p2_score):
lead = p1_score - p2_score
if p1_score > p2_score and lead > score_dif:
score_dif = lead
elif p1_score < p2_score and abs(lead) > score_dif:
score_dif = lead
i += 1
else : continue
My code is giving the correct answer for all the testcases ive manually inputed and is still not getting accepted, please check it out and if there’s a mistake, cam somebody point it out ? !
I did it without use of arrays in a much small way.
The problem statement is pretty much vague. We need to sum up all the points up to the current round, find the lead at the end of the round, compute the lead and display the maximum lead out of the calculated leads and the the corresponding winner.
Can anyone explain to me what’s wrong in my code ? pls
#include<bits/stdc++.h>
using namespace std;
int main()
{ int t,a,b,i,p=0;
int s1=0,s2=0,s3=0,s4=0;
int main()
{
int t,a,b,c=0,d=0;
int arr[10005];
scanf("%d",&t);
for(int i=0;i<t;i++)
{
scanf("%d%d",&a,&b);
c=c+a; //This Will Save All the Score Of Player 1 in all round
d=d+b; //This Will Save All the Score Of Player 1 in all round
arr[i]=c-d; //This store lead in each round and save it into a array
}
int max=*std::max_element(arr,arr+t); //This will find the maximum lead by Player 1
int min=*std::min_element(arr,arr+t); //This will find the max lead by Player 2
min=abs(min); //This Will take the positive value of player 2 as it will be negative
if(max>min) //Check If Player1 Lead>Player 2 Lead if Yes Print 1 else 2
{
printf("%d %d\n",1,max);
}
else
{
printf("%d %d\n",2,min);
}
return 0;
}