Getting tle during submission

Hii…

I am doing this question from hackerearth…

I have used recursion+memoization… to solve this problem…
I have used map for memoization…
This is my submission…
https://www.hackerearth.com/submission/51684573/

It is showing tle in 3 out of 20 test cases…

Please see this…
Can some improvement be done in this code… so that this question could be solved by recursion+memoization…
Thanks

Hey @ashishnnnnn ,
Your code is not working for higher values . Try Doing this problem in less time complexity .
Try to find a workaround than sorting

Hii… Could you suggest something…
I am not getting any idea… if i am not considering Sorting…