# BZOJ2802/POI 2012 Warehouse Store

n<=250,000，0<=Ai<=10^9，0<=Bi<=10^9.

Solution

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long
#include<queue>
using namespace std;
inline void rd(int &res){
res=0;char c;
while(c=getchar(),c<48);
do res=(res<<1)+(res<<3)+(c^48);
while(c=getchar(),c>=48);
}
inline void print(int x){
if(!x)return ;
print(x/10);
putchar((x%10)^48);
}
inline void sc(int x){
if(x<0){x=-x;putchar('-');}
print(x);
if(!x)putchar('0');
putchar('\n');
}
const int M=250005;
struct node{
int v,id;
bool operator<(const node &tmp)const{
return v<tmp.v;
}
};
priority_queue<node>Q;//大顶堆
int A[M],n,B[M];
int main(){
int i,j,k,a,b,ans=0,tot=0;
scanf("%d",&n);
ll sum=0;
for(i=1;i<=n;i++)scanf("%d",&A[i]);
for(i=1;i<=n;i++)scanf("%d",&B[i]);
for(i=1;i<=n;i++){
a=A[i],b=B[i];
sum+=a;
if(sum>=b){
sum-=b;
ans++;
Q.push((node){b,i});
}
else if(!Q.empty()){
int x=Q.top().v;
if(x>b){
Q.pop();
Q.push((node){b,i});
sum+=x-b;
}
}
}
while(!Q.empty()){
node x=Q.top();Q.pop();
A[tot++]=x.id;
}
sort(A,A+tot);
printf("%d\n",ans);
for(i=0;i<tot;i++)printf("%d ",A[i]);
puts("");
return 0;
}