比赛 2024暑假C班集训7 评测结果 WWWTTTTTTT
题目名称 买卖 最终得分 0
用户昵称 彭欣越 运行时间 14.787 s
代码语言 C++ 内存使用 6.10 MiB
提交时间 2024-07-07 11:59:14
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,cnt1,mk1[100010],mk2[100010],flag;
ll res,c[100010],d[100010];
struct node {
    ll x;
    int idx;
};
bool cmp1 (node x,node y) {
    return x.x<y.x;
}
bool cmp2 (node x,node y) {
    return x.x>y.x;
}
node a[100010],b[100010];
int main () {
    freopen("buy.in","r",stdin);
    freopen("buy.out","w",stdout);
    cin >> n;
    for (int i=1;i<=n;i++) {
        cin >> a[i].x;
        c[i]=a[i].x;
        a[i].idx=i;
    }
    for (int i=1;i<=n;i++) {
        cin >> b[i].x;
        d[i]=b[i].x;
        b[i].idx=i;
    }
    sort(a+1,a+n+1,cmp1);
    sort(b+1,b+n+1,cmp2);
    //cout << b[1].x <<endl;
    for (int i=1;i<=n;i++) {
        cnt1++; 
        ll sum=0;
        for (int j=1;j<=n;j++) {
            ll t=0;
            if (mk2[j]==1||b[j].idx<a[i].idx) continue;
            for (int k=a[i].idx+1;k<=n;k++) {
                if (mk2[k]==1) continue;
                for (int v=cnt1+1;v<b[j].idx;v++) {
                    //cout << 1 <<endl;
                    if (b[j].idx=k) break;
                    t=max(t,b[j].x-c[v]+d[k]-a[i].x);
                } 
            }
            //cout << t <<' '<< b[j].x-a[i].x <<endl;;
            if (t<=b[j].x-a[i].x) {
                res+=b[j].x-a[i].x;
                mk2[j]=1;
                break;
            }
        }
    }
    cout << res <<endl;
    return 0;
}