Please check my solution of mstick id=2174090 here i am using merge_sort procedure to find max-min where my merge only find max or min means complexity of my merge is O(constt) or O(1) we can say.

void merge(int *arr,int p,int q,int r)

{

int L=arr[p],M=arr[q+1],R=arr[r];

if(arr[p]>arr[q+1])

{

arr[p]=M;

arr[q+1]=L;

}

if(arr[r]<arr[q])

{

arr[r]=arr[q];

arr[q]=R;

}

}

but again i am getting TLE why? since my program also find max or min O(lgn).PLZ HELP!!!

Kindly post your question on the respective editorials. It will get answered better there. Here’s the link to the editorial: http://discuss.codechef.com/questions/9722/mstick-editorial

Thanks 4 helping…