这题用的贪心,但是只有10分,看了题解以后感觉贪心一样的,然后修改了一下,但是还是和之前一样只有10分。
求助qwq,代码如下
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
#define ri register long long
#define ll long long
ll n,cnt,b,s;
ll a[250010],ans[250010];
struct node{
ll c,d;
};
bool operator <(const node &x,const node &y){
return x.c<y.c;
}
priority_queue<node>q;
inline void read(ll &x){
x=0;int f(0);char ch=getchar();
while(ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
while(ch>='0'&&ch<'9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
x=f?-x:x;
}
int main(){
read(n);
for(ri i=1;i<=n;i++) read(a[i]);
for(ri i=1;i<=n;i++){
s+=a[i];
read(b);
if(b<=s){
s-=b;
q.push((node){b,i});
}
else if(!q.empty()&&q.top().c>b){
s+=q.top().c-b;
q.pop();
q.push((node){b,i});
}
}
while(!q.empty()){
ans[++cnt]=q.top().d;
q.pop();
}
sort(ans+1,ans+1+cnt);
printf("%lld\n",cnt);
for(ri i=1;i<=cnt;i++)
printf("%lld ",ans[i]);
return 0;
}