Finding median of sub arrays taking too much time
Not related to performance, but never ever do this:

#include &lt;bits/stdc++.h&gt;

using namespace std;


For reference see these Q&amp;A at Stack Overflow:


Why should I not #include &lt;bits/stdc++.h&gt;?
Why is “using namespace std;” considered bad practice?