COD32017 CODA2017 Getting WA

Need to know on which inputs does my solution fails.

Q1:https://www.codechef.com/PRCD1701/problems/COD32017/
my solution: https://www.codechef.com/viewsolution/13122779

Q2:https://www.codechef.com/PRCD1701/problems/CODA2017/
my solution: https://www.codechef.com/viewsolution/13117798

In question 2 here is the case where your code fails:

10

1345 5678 12 24 14 987 2 4 2 456

Your output:2 2 4 12 14 24 456 987 1345 5678

        264

Required Output:2 2 4 12 14 24 456 987 1345 5678

            257

Second number differs.
moreover for large numbers sorting is not performed in your case.

2 Likes

First question:

Input:
1
1
12

Correct Output: 0
Your output: 1 

Second question:
Input:
1
4
65 38 13 38
Correct answer: 23
Your answer: 19
1 Like

Ya I too think that it’s not necessary to include this type of case… I have done this question… I didn’t considerd case of less than 50 total weight… Coz it was clearly given that sum of weights has to be >=50 aka atleast 50

although i couldn’t find a test case but i found 1 other thing…

ur answer changes according to values of n… in my case it gives me runtime error !!!

urs: my answer:

input:
1
3
1 1 50
output: 2 output:2

1
4
1 1 50
output: 3 output: RUNTIME ERROR (for obvious)

1
5
1 1 50
output: 3 output: RUNTIME ERROR (for obvious)

“for large numbers sorting is not performed in your case” due to int return type of func binarysearc() ?

got the point in 2nd question but in 1st question it is given that On every day, it is guaranteed that the total weight of all of the items is at least 50 unit

1 Like

due to int return type of compare used during qsort

That’s why you have to print 0 if it is less than 50.

can we have 2 similar numbers in input ??

coz i did everything right but took map coz i thought 2 similar elements would not come…

@bansal1232 can we have more than 1 similar elements in input for second question…

1
4
2 7 4 2 like this ?

Yes! We can have!

Wait! I fail to understand this. If the input guarantees that weight will be atleast 50, whats the point in considering case of items less than 50 and give output of 0 on that? Am I missing something? Can you explain it, please :slight_smile: ?

Ok guys! Give me some time! I will try to debug your code again.

I actually debugged his code, tried testing and lol, I was literally unable to find a failing case. Try n see if ur “TC finding magic” works. And yes, just clarifying in case of misunderstanding, I asked about your test case, not the code. :slight_smile:

Wait…n is the number of items. You must provide n lines of integers as weights. I think if the number of input weights is less than weight, then the error is in test case. Kindly re-check the validity of your test case by reading input section :slight_smile:

exactly that’s what i am trying to prove !!!..

though all test case pass his code… but there’s a problem with the logic in his code that even on giving less numbers than ’ n ’ his code still gives a output…

it shud nt give a output… i am figuring out a different thing… not providing any test case… @vijju123

I have test every test case but only difference is got the mentioned above problem. Your solution is 100% correct but only failing when we sum id less than 50. I assure that there must be some flaw in author test cases or framing in question otherwise your logic is right.

I agree with @bansal1232. I literally tried every corner case I could come up with. His code passed all my test cases.