ANUMLA - Editorial

Since all the elements of the array are positive integers. Can we sort the subsets and get the first smallest N numbers ? have I understood the problem correctly ?

1 Like

Can anyone tell me what is wrong with following approach?

First check if there are more than 1 zeros. If there are two zeros then ‘0’ is the first element
otherwise if only one zero is found then the smallest non-zero positive element of given array is the first element of our ans.

Now subtract this min element from all other elements of given array. Again find the smallest positive and non-zero element it is the 2nd element and so on…

Please correct me if I am wrong!

Thank you!

Weak test cases for this question…
My logic is completely wrong but it passed in the practice section.
one of the test case is 1 , 3 , 0 1 1 2 2 3 3 4
giving 1 1 3 but correct answer is 1 1 2 .

sol link : CodeChef: Practical coding for everyone

4 Likes

Can anyone provide me a good corner case where my solution fails? I’m getting WA.

Link to solution: CodeChef: Practical coding for everyone

Thanks in advance :slight_smile:

Can anyone give me a tricky/corner test case for this question.
I am getting WA.

can anyone explain the algorithm with example???

Can anyone please tell why the code is giving RTE sQbNRz - Online C++ Compiler & Debugging Tool - Ideone.com

Can we apply the following algorithm?
The maximum element (say max) in the sumset will be equal to sum of all elements in required array (since all elements are +ve). we know the value of N. Then subtracting max from next N largest element will give us the value of N elements in a array…
P.S correct me if i am wrong

YSYAst - Online C++ Compiler & Debugging Tool - Ideone.com ! for all test cases given above this gives the right answer … can anyone reckon me the test case where i am wrong?

sum of the test cases i worked on are :-

8

3

0 1 1 1 2 2 2 3

3

0 1 2 3 3 4 5 6

3

0 1 100 1000 101 1001 1100 1101

4

0 1 2 3 4 3 4 5 5 6 7 6 7 8 9 10

4

0 1 1 2 2 2 3 3 3 3 4 4 4 5 5 6

2

1000000000 1000000000 2000000000 0

1

0 21

2

0 0 0 0

Why s.erase(s.begin()) is not written in else part of the author’s solution?? Can anyone please explain?!!

Why my logic is not working (getting runtime error.)…

Please help me out…

logic :- As we have the size of array (which is lost) then numbers present apart from the first one (which is always 0) the numbers from index (1) <…as index 0 the number is zero…> to N (size of lost array) we can have the numbers lost…

For eg.

line 1 :1

line 2 :3

line 3 :0 1 2 3 3 4 5 6

Ans :(1,2,3)(…after that the numbers would the sums of these numbers…)

My solution is : CodeChef: Practical coding for everyone

Can anyone tell me why i am getting runtime error?
Link to my code is CodeChef: Practical coding for everyone

i tried to sorted the input array in descending order and then subtract elements in 1 to n from 0: input[i]-input[0]…this gives me the n required elements…please tell me what is wrong with this approach

What if we sort the array in descending order and then subtract each element from i=1 to n from element at i=0…
each element = sorted_input[0]-sorted_input[i] from i=1 to i=n

1 Like

For most of the test cases my code is working fine. I even checked for the end cases. But it is giving wrong answer. Can someone please help me to find the problem in the code or just provide some cases for which my code is not working. Any help is greatly appreciated.

https://www.codechef.com/viewsolution/11587934

can anybody explain me the time complexity part …why log(2^n)is multiplied with 2^n?
thank you

I approach the problem with the similar idea to the solution but I’m getting WA.Can anyone please help me?

https://www.codechef.com/viewsolution/15146067

followed the editorial… getting sigsev

https://www.codechef.com/viewsolution/15146067

followed the editorial… getting sigsev

here in PREREQUISITES it says heap… what is the use of heap here ??

1 Like