https://www.codechef.com/ZCOPRAC/problems/ZCO13003/

This is my first post here, so I apologize in advance if I am breaking any rules.

Can you guys please help me find out whats wrong with my logic?

Here is what am trying to do …

given an array, first I sort it.

following sort - lets say the array looks like this:

[1,2,3,3,4,5,5,9,11] and the upper limit k is 9.

So I start with first element 1 and use the upperbound position to find the element e such that (e+arr[0]) > k.

My logic looks good to me on paper and yet I get runtime errors. Kindly help!

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