C++(clang++11) 解法, 执行用时: 6ms, 内存消耗: 388K, 提交时间: 2020-12-19 14:55:46
#include <cstdio> #include <algorithm> #include <queue> using namespace std; typedef long double ldb; typedef long long ll; const int N=1e3+5; const ll BASE=1e12; int n,a,b,w,va,wa,vb,wb,x[N],d[N]; ll ans1,ans2; priority_queue<ll,vector<ll>,greater<ll>> Qa,Qb; int main(){ scanf("%d%d%d",&n,&a,&b); scanf("%d%d%d%d%d",&w,&va,&wa,&vb,&wb); for(int i=1;i<=n;i++) scanf("%d",x+i); for(int i=1;i<=n;i++) scanf("%d",d+i); for(int i=1;i<=n;i++){ if(x[i]<0){ if(d[i]<0) ans1+=wa,Qa.push((-a+(x[i]-a))*vb-BASE); else Qa.push(-x[i]*vb-BASE); }else{ if(d[i]>0) ans2+=wb,Qb.push((b-x[i]+b)*va-BASE); else Qb.push(x[i]*va-BASE); } } if(Qa.empty()) ans2+=w; else if(Qb.empty()) ans1+=w; else{ while(w){ ll t1,t2; t1=Qa.top(); t2=Qb.top(); if(t1<t2){ //printf("%Lf %Lf\n",t1,t2); ans1+=min(wa,w); w-=min(wa,w); Qa.pop(); Qa.push(t1+2*(-a)*vb); }else{ ans2+=min(wb,w); w-=min(wb,w); Qb.pop(); Qb.push(t2+2*b*va); } } } printf("%lld %lld",ans1,ans2); return 0; }