You are viewing a single comment's thread. Return to all comments →
using namespace std;
int main() { int n,x,j; cin>>n; int *arr; float m; arr=new int[n];
cout<<setprecision(1)<<fixed; for(int i=0;i<n;i++) { cin>>arr[i]; x=arr[i]; j=i-1; while(arr[j]>x && j>=0) { arr[j+1]=arr[j]; j--; } arr[j+1]=x; int n1=i+1; if(n1%2==0) { float p=arr[n1/2]; float q=arr[(n1/2)-1]; m=(p+q)/2; } else { m=arr[n1/2]; } cout<<m<<endl; } return 0;
}
This is giving timeout error in all testcases except first 3. Please suggest what can be done if I want to use insertion sort method only, no heaps.
Seems like cookies are disabled on this browser, please enable them to open this website
Find the Running Median
You are viewing a single comment's thread. Return to all comments →
include
include
using namespace std;
int main() { int n,x,j; cin>>n; int *arr; float m; arr=new int[n];
}
This is giving timeout error in all testcases except first 3. Please suggest what can be done if I want to use insertion sort method only, no heaps.