Time Limit exceeded (TRAINSET)

Sorry,new here.
Please help me out with my TLE.
https://www.codechef.com/viewsolution/29141507

you are using an algorithm that has the time complexity of O(n^2)
since the elements are 25,000 which is 2.5 * 10^4 elements and there are 10 test samples in one test case, naturally this will be over the time because the number of operations are over 10^5.(10 * 2.5 * 10^4)
You need to come up with a method of lesser time complexity such as O(nlogn) or O(n).

1 Like