牛客小白月赛90 E-小A的任务

题目

思路

显然,k个b类任务至少要完成k个a类任务。但我们可以完成k个以上的a类任务,从中选择b类任务来完成。也就是说,我们只需要在每次询问时维护一个前k小的b类任务时间就可以解决这个问题。

#include<bits/stdc++.h>

using namespace std;
#define int long long
typedef long long ll;
#define pll pair<ll,ll>
#define endl "\n"
const int Inf =1e18;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;

inline ll read();
int a[N],b[N];
int ti[N];
bool vis[N];
void solve() {
    int n=read(),q=read();
    for(int i=1;i<=n;i++){
        a[i]=read();
    }
    for(int i=1;i<=n;i++){
        b[i]=read();
    }
    while(q--){
        int x=read();
        priority_queue<int>que;
        int now=0,ans=0,sum=0;
        for(int i=1;i<=x;i++){
            now+=a[i];
            que.push(b[i]);
            sum+=b[i];
        }
        ans=now+sum;
        for(int i=x+1;i<=n;i++){
            now+=a[i];
            que.push(b[i]);
            sum=sum+b[i]-que.top();
            que.pop();
            ans=min(ans,now+sum);
        }
        cout<<ans<<endl;
    }

}

signed main() {
//    ios::sync_with_stdio(false);
//    cin.tie(nullptr),cout.tie(nullptr);
    int tt = 1;
    //tt=read();
    while (tt--)
        solve();
}

inline ll read() {
    ll x = 0, ch = getchar(), f = 1;
    while (!isdigit(ch)) {
        if (ch == '-')
            f = -f;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值