I was solving http://www.codechef.com/problems/CD1IT1
I am using the following method of quickselect for kth order statistics. It was giving TLE while the normal sorting and returning the middle element got AC. Is’nt quick select supposed to be faster
using namespace std;
long long int swap(long long int &a,long long int &b)
long long temp=a;
long long partition(long long arr,int lo,int hi,int k)
long long pivot=arr[lo];
while(arr[i]<pivot && i!=hi)
long long n,*arr;
arr=new long long[n];
long long k;
Before asking such questions you should try to make an effort in finding out the time complexities of various algorithms.
The time limit is 1 second and a program can do computations roughly about the order of O(10^7).
I am sorry to say I have not completely read your code but I can assure you that quick sort is definitely not the fastest sorting algorithm. In case all the elements are already sorted or if they are in reverse order, quick sort will take a complexity of O(n^2). (Get a better understanding from this link http://geeksquiz.com/quick-sort/ ).
In the above question n has a maximum value of 10^5 and n^2 will be 10^10. (1 second will definitely be exceeded)
If you are looking for more optimum sorting algorithms you can refer merge sort (http://geeksquiz.com/merge-sort/) and heap sort (http://geeksquiz.com/heap-sort/)
For coding faster you can use the algorithm library available in C++ (http://www.cplusplus.com/reference/algorithm/sort/?kw=sort) which has a maximum time complexity of O(N*log2(N)).