## 10812 - Beat the Spread!

Moderator: Board moderators

### Re: 10812 - Beat the Spread!

i got AC.
Experienced poster

Posts: 136
Joined: Sat Nov 29, 2008 8:01 am

### Re: 10812 - Beat the Spread!

i need help.i just cant understand!!!!!

#include<stdio.h>

long x,y,s,d,n,i,a,b;

{
scanf("%ld%ld",&s,&d);
if(s>=d)
{
x=(s+d);
y=(s-d);
a=x/2;
b=y/2;
if((x%2==0) && (y%2==0) && (a>0) && (b>0))
printf("%ld %ld",a,b);
else
printf("impossible");
}
else
printf("impossible");
printf("\n");
a=b=x=y=0;
}

int main(void)
{
while(scanf("%ld",&n)==1)
{
for( i = 1 ; i <= n ; i ++)
{
}
}
return 0;
}
sms.islam
New poster

Posts: 19
Joined: Sat Oct 10, 2009 10:28 am

### Re: 10812 - Beat the Spread!

I got it!!!!! i think more about this easy problem. The addition of two number is always even.so why should i check it?
sms.islam
New poster

Posts: 19
Joined: Sat Oct 10, 2009 10:28 am

### Re: 10812 - Beat the Spread!

can any one say why um getting WA ?
Code: Select all
`#include<stdio.h>int main(){   long a,b,tst;   scanf("%d",&tst);   while(tst--){      int s,d;      scanf("%d %d",&a,&b);      s=a+b;d=a-b;      if((a+b)%2)printf("impossible\n");         else if((a-b)%2)printf("impossible\n");      else if(a<b)printf("impossible\n");      else printf("%d %d\n",s/2,d/2);   }   return 0;}`

one day...
kissu parina
New poster

Posts: 19
Joined: Thu May 20, 2010 8:58 am

### Re: 10812 - Beat the Spread!

#include<stdio.h>
int main()
{
long int t, s, d, a, c;
scanf("%d",&t);
while(t--)
{
scanf("%d %d", &s, &d);
a = (s - d) / 2;
if((s%2==0 && d%2!=0) || (s%2!=0 && d%2==0) || (s-d)<0) printf("impossible\n");
else
{ if(a < s-a){ c = a; a = s - a; }
printf("%d %d\n", a, c);
}
}

return 0;
}

This is my code I got WA . Please anybody help me.
rasel2707
New poster

Posts: 1
Joined: Sat Feb 05, 2011 6:32 pm

### Re: 10812 - Beat the Spread!

i m getting w.a..... here is my code[code][/code]

#include<stdio.h>
//#include<iostream.h>
int main()
{
int t,s,d,i,j;
scanf("%d",&t);
while(t>0)
{
scanf("%d%d",&s,&d);
if(s<d)
{
printf("impossible\n");
goto m;
}
for(i=d;i<=s;i++)
{
for(j=0;j<=d;j++)
{
if(i+j==s && i-j==d)
{
goto l;
}
}
}
printf("impossible\n");
goto m;
l: printf("%d %d\n",i,j);
m: t--;
}
// system("pause");
return 0;
}
shoaib7k
New poster

Posts: 10
Joined: Thu Aug 18, 2011 7:45 pm

### Re: 10812 - Beat the Spread!

Much easy problem. This samples might help.
Input:
Code: Select all
`1215 1088 9155 2220 1040 1275 2513 7888 2229999 111112365 12399 1113 19`

Output:
Code: Select all
`impossibleimpossibleimpossible15 526 1450 2510 3555 3335555 44446244 612155 44impossible`
PromeNabid
New poster

Posts: 13
Joined: Mon Jun 18, 2012 12:52 am

### Re: 10812 - Beat the Spread!

Can Anyone help me finding problem at this code? I got wrong answer every time . Help me please

#include <stdio.h>

int main()
{
long int n, s, d, difference, big, small;
int i, count=0;

scanf("%ld", &n);

for(i=0; i<n; ++i)
{
scanf("%ld %ld", &s, &d);

if(d>s)
{
printf("impossible");
}
else if(d==0 && s%2==0)
{
printf("%ld %ld\n", s/2, s/2);
}
else if(s%2==0 && d%2==1)
printf("impossible\n");
else if(d==0 && s%2==1)
printf("impossible\n");
else
{
difference=s-d;
if(difference%2==1)
{
printf("impossible\n");
continue;
}
big = difference/2 + d;
small = s - big;
printf("%ld %ld\n", big, small);
}
}
return 0;
}
sulaimansust
New poster

Posts: 4
Joined: Fri Jul 27, 2012 1:53 pm

### Re: 10812 - Beat the Spread!

line 16 is missing a newline.
brianfry713
Guru

Posts: 1765
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10812 - Beat the Spread!

Thanks Bro.
sulaimansust
New poster

Posts: 4
Joined: Fri Jul 27, 2012 1:53 pm

Previous