贪心---->后悔大法好。。具体来说,能卖就卖,卖不了,就去前面找,如果买得最多的比这个多,就把他的抢回来,卖给现在这个人。。好无厘头,但就是这种贪心方法。。。
#include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #include<queue> #define N 250000 #define ll long long using namespace std; ll n,kao[N+5],buy[N+5],sum=0,ans=0; priority_queue<ll> q; ll read() { ll sum=0,f=1;char x=getchar(); while(x<'0'||x>'9'){if(x=='-')f=-1;x=getchar();} while(x>='0'&&x<='9')sum=sum*10+x-'0',x=getchar(); return sum*f; } ll yjn() { freopen("wing.in","r",stdin); freopen("wing.out","w",stdout); n=read(); for(ll i=1;i<=n;i++) kao[i]=read(); for(ll i=1;i<=n;i++) buy[i]=read(); for(ll i=1;i<=n;i++) { sum+=kao[i]; if(sum>=buy[i]) { ans++; sum-=buy[i]; q.push(buy[i]); } else { if(q.empty())continue; ll t=q.top(); if(t>buy[i]) { q.pop(); q.push(buy[i]); sum+=t-buy[i]; } } } cout<<ans; } ll qty=yjn(); int main(){;}