Why are you doing so much in a very simple question? It can simply be done using this r refer this discussion here. The reason of your wrong answer is probably in this thread(the second link).
Your code gives wrong answer for cases like this:
2 3 2
500003 1234
500002 500004 5999
500003 1234
i.e. cases in which id>50000, it’s given that n1,n2,n3<=500000, not the ids!!
i know , but before looking into the solution i chose this way … no doubt from now on i ll follow your way of doing it …
but still i want to know why my code is showing the wrong ans ??
i ran each test case … even i reviewd my code many times but nothing budged
i know , but before looking into the solution i chose this way … no doubt from now on i ll follow your way of doing it … but still i want to know why my code is showing the wrong ans ??
i ran each test case … even i reviewd my code many times but nothing budged
No, you’re understanding wrong. WHat does the declaration int a[10]mean? It means that we can access all elements frm a[0] to a[9], but accessing a[10] or any other index is not possible because we are accessing the memory we haven’t allocated. Similarly in your code, you are declaring an array of 50,000. In this manner you are assuming that ids are maximum upto 50,000 which is not true as per the question.
and in the question they have given any constraint on values of ID’s !!!
for such a large values like you have given 500004 it is showing run time error …
The range of 50000 is given for the “Number of ids in the list”, not the range of id. You are getting rte because you are accessing an undefined location. See the comment by admin on the same page “No, ID can be any number that fits in a 4 byte signed integer.”