I don’t understand what is wrong with my code,why on submitting,i’m getting wrong answer.plz can anybody help me out.I’m new to codechef,and out of many problems i tried i always get wrong answer. Is it because of my approach or something else?plz can anyone help me out,m getting demoralised with these wrong answers.here’s link to my chefa solution-

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

Just a small problem in your bubblesort function. When i=0, (say) then j will go from 0 to <b-i, which is 0 to b-0=b. Hence j can be b-1. So j+1 will be b. and you compared a[j] and a[j+1] in your function. which means your will get a[b] sometime which is invalid. Since the size of the array is b, the max index can be b-1. If u want to have a test case where it fails try this 1 6 1 2 3 4 5 6 . Just correct that. And to remove tle from your next subtask try a better sorting function, faster input/output method like scanf and printf and actually u dont need this reverse function as well. You can simply start adding to sum from the end of your sorted array.

thankx,i completely got that.

cheers! all the best!

hey,can you tell me what really the subtask means,and how to accomplish it?does it means that an if condition has to be applied on the range of n,or a[i].

No, it just means that you have to optimize your code further to meet the input constraints. In this question in the first subtask 1000 points will be given and in the second one, say 1000000 are given, then bubblesort can be used to sort the array. So you have to make your code accordingly.