Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

The lead game

$
0
0

can i ask whats wrong with my code? i got WA

    #include<stdio.h>
#define max(a,b) (((a) > (b)) ? (a) : (b))
int a[2][10001];
int main()
{
 int t;
 scanf("%d",&t);
 for(int x=0;x<t;x++)
 {


         int b,c;
         scanf("%d%d",&b,&c);
         if(b>c){a[0][x]=1;a[1][x]=b-c;}
         else  {a[0][x]=2;a[1][x]=c-b;} 
 }
 int W,L(0);
 for(int x=0;x<t;x++)if(L<a[1][x]){L=a[1][x];W=a[0][x];}
 printf("%d %d\n",W,L);
return 0;
}

here the new code(after modified):

#include<stdio.h>
#define max(a,b) (((a) > (b)) ? (a) : (b))
int a[2][10001];
int main()
{
 int t,d(0),e(0);
 scanf("%d",&t);
 for(int x=0;x<t;x++)
 {
         int b,c;
         scanf("%d%d",&b,&c);

         if((b+d)>(c+e)){a[0][x]=1;a[1][x]=(d+b)-(c+e);}
         else  {a[0][x]=2;a[1][x]=(c+e)-(b+d);} 
         d+=b;e+=c;//printf("%d %d\n",d,e);
 }
 //for(int x=0;x<t;x++)printf("%d\n",a[1][x]);
 int W,L(0);
 for(int x=0;x<t;x++)if(L<a[1][x]){L=a[1][x];W=a[0][x];}
 printf("%d %d\n",W,L);
 scanf("%d",t);
}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>