52分 求条 RE
查看原帖
52分 求条 RE
1131953
dc_yangpengming楼主2025/7/23 10:34
#include<iostream>
#include<queue>
#define int long long
using namespace std;
struct node{
    int w,pos;
    bool operator<(const node x) const{
        return w<x.w;
    }
};
const int N=3e5;
int n,a[N],sum,ans;
node b;
priority_queue<node> q;
priority_queue<int,vector<int>,greater<int>> p;
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++){
        sum+=a[i];
        cin>>b.w;
        b.pos=i;
        if(sum>=b.w){
            q.push(b);
            sum-=b.w;
        }
        else{
            if(q.top().w<=b.w){
                continue;
            }
            else if(!q.empty()){
                sum+=q.top().w-b.w;
                q.pop();
                q.push(b);
            }
        }
    }
    while(!q.empty()){
        ans++;
        p.push(q.top().pos);
        q.pop();
    }
    cout<<ans<<endl;
    while(!p.empty()){
        cout<<p.top()<<" ";
        p.pop();
    }
    return 0;
}
2025/7/23 10:34
加载中...