W.A. in Aloknath and his Sanskars

HERE IS MY C++ CODE

   #include"stdio.h"
   #include"iostream"
   #include"stdlib.h"
   #include"algorithm"

   using namespace std;

 #define get(a) scanf("%lld",&a)
 #define yes printf("yes\n")
 #define no printf("no\n")

 int main()
{
	long long int t,n,tmp,p,i,j,k,a[22],sum,sump,itr;
	get(t);
	while(t--)
	{
		get(n);
                get(p);
                sum=0;
		for(i=0;i n)

			no;

		   else

			yes;

		}

		else
		{
			if(sum % p != 0 || p>n)
				no;
			else
			{
				tmp=sum/p;
				itr=p;
				sort(a,a+n);
				while(itr)
				{
					sum=tmp;
					for(i=n-1;i>=0 && sum !=0 ;i--)
					{
						if(a[i]<=sum && a[i]!= 0)
						{
							sum-=a[i];
							a[i]=0;
						}	
					}
					if(sum != 0)
						break;
					itr--;	
				}
				if(itr)
					no;
				else
				{
					for(i=0; i < n ; i++)
						if(a[i]!=0)
							break;
					if(i==n)
						yes;
					else
						no;
				}	
			}		
		}
	}
	return 0;	
}

I TRIED TO COVER ALL THE TEST CASES I FOUND PLZ SUGGEST ANY COUNTER TEST CASE

Try these Cases :

10

9 6

6 2 2 5 2 7 3 1 8

10 4

9 7 5 6 0 3 8 9 7 2

10 2

2 2 6 5 1 8 9 4 2 1

8 6

1 7 2 8 8 0 5 4

10 7

0 7 0 1 5 5 5 4 6 3

10 2

2 2 6 0 6 1 8 8 9 0

7 6

6 1 3 1 1 0 5

9 3

0 2 9 9 9 4 4 1 1

3 7

1 4 1

6 4

1 2 6 0 2 9

Your Output :

no

no

no

no

no

no

no

no

no

no

Answer :

no

yes

yes

no

no

yes

no

yes

no

no

2 Likes

Also try
1
6 2
4 4 5 6 8 9

How about

1
6 2
4 9 10 17 17 19

Your code outputs no

@achaitanyasai
@apptica
& @mjbpl
I got it…!!! I was checking poor test cases :frowning: …!! Can anyone suggest how to find such corner test cases???

Hello friends :slight_smile:
Here is the link to my code
http://www.codechef.com/viewsolution/5602196
I’ve tried almost all corner test cases and even the ones mentioned above but still my code gives a WA. Please tell me where am I going wrong.

Well My code passed all of mine and all of the above… still WA for one of the subtasks (Task 1 - subtask 2) on codechef.

one of my submission: CodeChef: Practical coding for everyone

My algorithm was to
find all subsets of the given sanskar intensities
filter out the subsets having sum = sum(sanskars)/K
find such K subsets and check if all the sanskars have been used.

Anything I missed out?

My code is not passing for the last case only…for me it seems correct… point out the mistake please…
Link to code:CodeChef: Practical coding for everyone

Hey, I saw the editorial and understood the solution . But I used Greedy-Approach to solve the problem . Can anyone give me a testcase on which my solution is failing. (Try to avoid 0 based testcases as I am making some very obvious conceptual flaw.)And yaa its passing the above mentioned testcases.

I guess these are not corner cases, what I have done was : I have generated test cases using a script and checked your code with the accepted one. That’s all I did !!!, but you need to think(or try some random small cases using pen paper and check with them) if you didn’t have accepted code with you.

1 Like

i think it should be “6 2…” instead of “7 2…”

Did you try this case :

1

1 8

0

Answer :

no

it’s printing “yes”!

Answer is no !!

Why?? It should be “yes” I guess because the sum is 0!

A “sanskar with 0 intensity” and “no sanskar” are not the same things!

Thanx! But even correcting this didn’t solve the problem! I’m getting 3 AC’s but still it is being evaluated as a WA.

even after correcting your code still prints “yes”
Take a look at 3rd case in lSfLUs - Online C++ Compiler & Debugging Tool - Ideone.com

I modified my code after you told me that! Take a look at my modified code - CodeChef: Practical coding for everyone

@faudar65 yes