编辑代码

#include <iostream>
using namespace std;
int main() {
    int L;cin>>L;
    int a[L+5]={0},b[L+5]={0},c[L<<1]={0};
    for(int i=1;i<=L;++i){
        cin>>a[i];
    }
    for(int i=1;i<=L;++i){
        cin>>b[i];
    }
    int i=1,j=1,k=1;
    while(k<=2*L+1){
        if(i==L+1){
            c[k++]=b[j++];
        }else if(j==L+1){
            c[k++]=a[i++];
        }else {
            if(a[i]>b[j]) c[k++]=b[j++];
            else if(a[i]<b[j]) c[k++]=a[i++];
            else {
                c[k++]=a[i++];
                c[k++]=b[j++];
            }
        }
    }
    for(int i=1;i<=2*L;++i){
        cout<<c[i]<<' ';
    }
    cout<<'\n'<<c[(2*L)/2];
	return 0;
}