getting a wrong answer

wa

#1

question is
http://www.codechef.com/problems/MARCHA1/

my sol is
http://www.codechef.com/viewsolution/5150997

dont know why i am getting a wrong answer…already checked all test cases given…


#2

Oh! It gives you a wrong answer when m=0 but n!=0 . Say t=5, m=5, n=0 , 1, 2, 3, 4, 5. The answer should be No as you cannot make zero with these bank notes. Your code outputs yes though.
Solution :- Add an if condition, simple!


#3

Hi dude, checking for the sample input test cases doesn’t guarantee that your solution will be right(AC). Pranjal has already pointed out the test case for which your code fails. Also, while taking inputs you are printing an extra line for each input which isn’t required.


#4

#include<stdio.h>

void sort(int a[],int n)
{

int i,j,temp;
for(i=0;i<n;i++)
{
	for(j=i+1;j<n;j++)
	{
		if(a[j]<a*)
		{
			temp=a[j];
			a[j]=a*;
			a*=temp;
		}
	}
}

}

int main()
{

int i,j,k,s1,q,s2,t,m,n,a[25];
scanf("%d",&t);
while(t--)
{
	s1=0;k=0;s2=0;
	scanf("%d%d",&n,&m);
	if((n==0)||(m==0))
	{
		printf("No

“);
continue;
}
for(i=0;i<n;i++)
scanf(”%d",&a*);
sort(a,n);
//for(i=0;i<n;i++)
//printf("%d “,a*);
//printf(”

“);
for(i=0;i<n;i++)
{
if(a*==m)
{
s1=1;
break;
}
if(a*>m)
{
q=i-1;
break;
}
if(a*<m)
s2+=1;
}
//printf(”%d
",q);
if(s1==1)
{
printf("Yes
“);
break;
}
if(s2==n)
q=n-1;
//printf(”%da

",q);
if(s1==0)
{
for(i=q;i>0;i–)
{ k=0;
k+=a*;
for(j=i-1;j>=0;j–)
{
k+=a[j];
if(k>m)
k-=a[j];
if(k==m)
break;
}
if(k==m)
break;

		}
	}
		if(k==m)
		printf("Yes

");
else
printf("No
");
}
return(0);
}

i made some changes…but still nt working…


#5

Fails for this test case, the output for the 2nd case should be No --> (Link) http://ideone.com/wz91x1


#6

but in my compiler in dev c++ the answer for 2nd case…is coming NO…
i don’t know how this is possible that answer are not matching…for this case…


#7

i have checked it twice…its coming no


#8

Enter the same test cases(in the same order) and I am pretty sure you will get the above results if the code is same.


#9

again coming NO…just entered the same test cases…in same order


#10

http://www.codechef.com/viewsolution/5153711

here is the last code uploaded by me…i am checking ur cases in this one…


#11

Again a test case for which your code fails :slight_smile: http://ideone.com/L0aDJ1


#12

okay…i will get through the algo again…
thank u for ur help…