## 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

can any1 help me please ,with what is wrong about my code.here is my code-
#include<stdio.h>

int main()

{
int i,x,s,d,sum,min;

while(scanf("%d",&x)==1)

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

sum=(s+d);
min=(s-d);

if(s>d || s==d ) {

if((sum%2==0) && (min%2==0))

{

printf("%d\n",(s+d)/2);
printf("%d\n",(s-d)/2);
}

else printf("impossible\n");
}
else if(s<d) printf("impossible\n");}

}
return 0;
}
nhrahi
New poster

Posts: 6
Joined: Tue Aug 25, 2009 7:38 pm

### 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: 17
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.
Check input and AC output for hundreds of problems on uDebug!
brianfry713
Guru

Posts: 3863
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

### Re: 10812 - Beat the Spread!

#include<stdio.h>

int main()
{
int i,sum,t,a,b,dif;
scanf("%d",&t);
for(i=1;i<=t;i++){
scanf("%d %d",&sum,&dif);
if(dif<=0 ||(dif+sum)%2==1 || sum<=0 || dif>sum)
printf("impossible\n");
else {

a=(dif+sum)/2;
b=sum-a;
if(a>=0 && b>=0){
if(a>b)
printf("%d %d\n",a,b);
else{printf("%d %d\n",b,a);}}
}
}
return 0;
}

SifatRuet12
New poster

Posts: 3
Joined: Mon Jul 01, 2013 12:42 pm

### Re: 10812 - Beat the Spread!

Input:
Code: Select all
`10 0`
Output should be:
Code: Select all
`0 0`
Check input and AC output for hundreds of problems on uDebug!
brianfry713
Guru

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

### Re: 10812 - Beat the Spread!

guys i need help i dnt have any idea what's wrong with my code it works perfectly
#include <iostream>
using namespace std;

int main(){
long int a,b,t;
cin>>t;
while(t--){
cin>>a>>b;
long int s=(a+b)/2,m=(a-b)/2;
if(s>0 && m>0){
cout<<s<<m<<endl;}
else
cout<<"impossible"<<endl;

}
}

after submitting the code they keep on showing that the ans is wrong
k23456
New poster

Posts: 1
Joined: Thu Sep 19, 2013 11:38 am

### Re: 10812 - Beat the Spread!

There should be a space in between numbers in the output
Check input and AC output for hundreds of problems on uDebug!
brianfry713
Guru

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

PreviousNext