日常刷水…
简单贪心,考虑用一个堆维护已选的客人,若能选则选,不能就取堆中购物数最多的客人不取,取当前客人即可。
用了pbds还是好慢啊TAT。
代码:
#include<bits/stdc++.h>
#include<ext/pb_ds/priority_queue.hpp>
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,int> pli;
const int N=250005;
int read(){
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
__gnu_pbds::priority_queue<pli>q;
int a[N],b[N],c[N];
int main(){
int n=read(),ans=0;
for (int i=1;i<=n;i++) a[i]=read();
ll res=0;
for (int i=1;i<=n;i++){
b[i]=read(); res+=a[i];
if (res>=b[i]) res-=b[i],q.push(mp(b[i],i));
else{
if (!q.empty()){
int x=q.top().first;
if (x>b[i]) res+=x-b[i],q.pop(),q.push(mp(b[i],i));
}
}
}
while (!q.empty()){
c[++ans]=q.top().second; q.pop();
}
sort(c+1,c+1+ans);
printf("%d\n",ans);
for (int i=1;i<ans;i++) printf("%d ",c[i]);
printf("%d\n",c[ans]);
return 0;
}