1029. Median

#include<cstdio>
const int N=1000004;
long int x[N],y[N],med,m,n;
int main(){
  scanf("%d",&m);for(int i=0;i<m;++i) scanf("%ld",x+i);
  scanf("%d",&n);for(int i=0;i<n;++i) scanf("%ld",y+i);
  int  nth=(m+n-1)/2+1,cur=0,xi=0,yi=0;
  while(cur<nth &&xi<m &&yi<n){
    med = x[xi]<y[yi]?x[xi++]:y[yi++];
    ++cur; }
  if(cur<nth &&xi<m) med= x[xi+nth-cur-1],cur=nth;
  if(cur<nth &&yi<n) med= y[yi+nth-cur-1];
  printf("%ld",med);
}

你可能感兴趣的:(1029. Median)