You are not logged in. Please login at www.codechef.com to post your questions!

×

The Lead Game not working.Help.

include <stdio.h>

int cmp (int a,int b) { return ((int)a-(int)b); }

int main(void) { int t,a,b,c,e,f,g,h; scanf ("%d",&t); int d [t][2],i [t][2],j [t]; for (c=0;c <t;c++) {="" scanf="" ("%d="" %d",&a,&b);="" if="" (a="" <="0" ||="" b="" <="0" ||="" a="">1000 || b>1000) { abort (); } d [c][0]=a;d [c][1]=b;i [c][0]=0;i [c][1]=0; i [c][0]=i [c][0]+d [c][0]; i [c][1]=i [c][1]+d [c][1]; } for (c=0;c <t;c++) {="" j="" [c]="i" [c]="" [0]-i[c]="" [1];="" }="" qsort="" (j,t,sizeof="" (int),cmp);="" e="j" [t-1];g="abs" (e);="" f="j" [0];h="abs" (f);="" if="" (g="">h) { printf ("1 %d",g); } else if (g==0 && f==0) { abort (); } else { printf ("2 %d",h); }

return 0;

}

Why am i getting Wrong Answer.Please help.

asked 26 Jul, 11:48

kriskhundu's gravatar image

0★kriskhundu
01
accept rate: 0%


hi kriskhundu , if u can generate a url of your code on ideone then it would be helpful for us to debug

link

answered 26 Jul, 13:12

mrinal_29's gravatar image

3★mrinal_29
01
accept rate: 0%

The question asks you to find the max lead on the basis of total score till a round. And, the total score of a round is the cumulative sum of all the scores till that round, including it.

Looking at your code, it seems like you are storing the cumulative score in the array $i[t][2]$. But there's a problem in the implementation. Change this

 i [c][0] = i [c][0] + d [c][0];
 i [c][1] = i [c][1] + d [c][1];

To this

 i [c][0] = i [c-1][0] + d [c][0];
 i [c][1] = i [c-1][1] + d [c][1];

Also, take care of the case when $c = 0$ ($c-1$ will be $-1$ in that case), and then your code will be fine.

The reason that your code gives a right answer in the sample test case is that the max lead in it happens in the first round itself, so there is no need of a cumulative score. But this may not happen always, giving a wrong answer in the other cases.

link

answered 26 Jul, 13:58

c_utkarsh's gravatar image

4★c_utkarsh
8293
accept rate: 11%

edited 26 Jul, 14:01

1

Thank you Mr Lifesaver :)

(26 Jul, 21:26) kriskhundu0★

Well, you can show your gratitude by accepting the answer.

(26 Jul, 22:26) c_utkarsh4★
r=[]
s=[]
for t in range(int(input())):
    a,b=map(int,raw_input().split())
    if a>b:
        c=a-b
        r.append(c)
        s.append(1)
    elif b>a:
        c=b-a
        r.append(c)
        s.append(2)
e=[list(l) for l in zip(r,s)]
print e
q=max(e)
print q[1],q[0]

my code for lead game in python.. wrong answer help needed.

link

answered 11 Aug, 00:12

sabi_91's gravatar image

0★sabi_91
11
accept rate: 0%

edited 11 Aug, 04:44

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,557
×16
×1

question asked: 26 Jul, 11:48

question was seen: 154 times

last updated: 11 Aug, 12:39