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

×

TLG:code gives correct output still ans is wrong plz help me find whats wrong in program

link text

Above lies the link to problem statement. I'm providing the code below, kindly help me. Thank you...

#include<stdio.h>
int main()
{
    int N=0,i=0,W=0,L=0,s=0,t=0;
    scanf("%d",&N);
    int mS=0,mT=0;
    int Si[N],Ti[N],maxS[N],maxT[N];
    for(i=0;i<N;i++)
    {
        Si[i]=0; Ti[i]=0;
        scanf("%d %d",&s,&t);
        if(i!=0)
        {
            Si[i]=Si[i-1]+s;
            Ti[i]=Ti[i-1]+t;
        }
        else
        {   Si[i]=s;
            Ti[i]=t;
        }
        if(Si[i]>Ti[i])
        {   maxS[i]=Si[i]-Ti[i];
            if(i==0)
                mS=maxS[i];
            if(i!=0 && maxS[i]>maxS[i-1])
                mS=maxS[i];
        }
        else
        {   maxT[i]=Ti[i]-Si[i];
            if(i==0)
                mT=maxT[i];
            if(i!=0 && maxT[i]>maxT[i-1])
                mT=maxT[i];
        }
    }
    if(mS>mT)
    {   W=1;L=mS;}
    else
    {   W=2;L=mT;}
    printf("%d %d",W,L);
}

asked 10 Aug, 23:21

anuj_it's gravatar image

0★anuj_it
1
accept rate: 0%


These two lines are wrong:

if(i!=0 && maxS[i]>maxS[i-1])
if(i!=0 && maxT[i]>maxT[i-1])

... you need to compare to more than the immediately previous result.

link

answered 11 Aug, 01:12

joffan's gravatar image

4★joffan
4847
accept rate: 10%

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:

×59
×55
×17
×1

question asked: 10 Aug, 23:21

question was seen: 53 times

last updated: 10 Aug, 23:21