You are using bubble sort.
It has a time complexity of O(n^2)
It won’t work because of the time limit.
Try to use a O(n log(n)) complexity algorithm like merge sort.
Here’s my solution using merge sort, http://www.codechef.com/viewsolution/3306706
There are predefined functions in almost all the languages that perform sorting in O(n log(n)).
For example, sort() function in C++ (Header: < algorithm >)
I would suggest that you also use these functions for the sake of knowledge.
But it is very important that you understand merge sort, quick sort and many more sorting algorithms and their complexities. Knowledge of sorting algorithms is important.
Here are a few sorting algorithms:
And many more