题解 CF1305A 【Kuroni and the Gifts】

· · 题解

因为 a_i,b_i 两两不同,所以排序后

a_1 < a_2 <\dots < a_n b_1 < b_2 <\dots < b_n

加起来

a_1+b_1 < a_2+b_2 <\dots < a_n+b_n

满足题意两两不等。

综上,直接排序,然后输出和即可。

#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
    re int t=0;
    re char v=getchar();
    while(v<'0')v=getchar();
    while(v>='0'){
        t=(t<<3)+(t<<1)+v-48;
        v=getchar();
    }
    return t;
}
int t,n,a[100002],b[100002];
int main(){
    t=read();
    while(t--){
        n=read();
        for(re int i=1;i<=n;++i)a[i]=read();
        for(re int i=1;i<=n;++i)b[i]=read();
        sort(a+1,a+n+1);
        sort(b+1,b+n+1);
        for(re int i=1;i<=n;++i)printf("%d ",a[i]);
        putchar('\n');
        for(re int i=1;i<=n;++i)printf("%d ",b[i]);
        putchar('\n');
    }
}