比赛 2024暑假C班集训7 评测结果 AAAAAAAAAA
题目名称 买卖 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 0.242 s
代码语言 C++ 内存使用 4.72 MiB
提交时间 2024-07-07 11:25:32
显示代码纯文本
#include <bits/stdc++.h> 
using namespace std;
#define ll long long
#define pii pair<ll,int>
const int N = 1e5+10;
const ll inf = 1e17,mod = 998244353;

ll read(){
    ll x = 0,f = 1;char c = getchar();
    for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
    for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
    return x * f;
}


int n;
ll a[N],b[N],ans;
priority_queue<ll,vector<ll>,greater<ll> >q1;
int main(){
    freopen("buy.in","r",stdin);
    freopen("buy.out","w",stdout);
    n = read();
    for(int i = 1;i <= n;i++)a[i] = read();
    for(int i = 1;i <= n;i++)b[i] = read();
    for(int i = 1;i <= n;i++){
        q1.push(a[i]);
        if(q1.top() < b[i]){
            ans += b[i] - q1.top();
            q1.pop();
            q1.push(b[i]);
        }
    }
    printf("%lld\n",ans);
    
    
    return 0;
    
}