Codeforces Round #429 (Div. 2) 840A Leha and Function(贪心)

时间:2021-01-14 23:22:48

这题真的很简单,直接观察一下样例,就是尽可能使两个数差距大,所以就排两个序解决,你可以自己验证下是不是这样.
唉,被编译器坑了,至少少了我300分,本来int不能被lld输出,自己机子上居然可以,搞得wa在test1十几次,气死我了.

/* xzppp */
#include <bits/stdc++.h>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson MAXN,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
const int MAXN = 2*100000+17;
const int INF = 0x7fffffff;
const int MOD = 1e9+7;
LL a[MAXN];
struct dap
{
    LL num,id;
}b[MAXN];
bool cmp1(dap x ,dap y)
{
    if(x.num==y.num)
        return x.id>y.id;
    return x.num<y.num;
}
bool cmp2(dap x,dap y)
{
    return x.id<y.id;
}
int main()
{
    //FFF
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
        scanf("%lld",a+i);
    for (int i = 0; i < n; ++i)
    {
        scanf("%lld",&b[i].num);
        b[i].id = i;
    }
    sort(a,a+n);
    sort(b,b+n,cmp1);
    for (int i = 0; i < n; ++i)
    {
        b[i].num = a[n-1-i];
    }
    sort(b,b+n,cmp2);
    for (int i = 0; i < n-1; ++i)
        printf("%lld ",b[i].num);
    cout<<b[n-1].num<<endl;
    return  0;
}