C++ 解法, 执行用时: 33ms, 内存消耗: 5364K, 提交时间: 2021-10-06 15:37:18
#include<bits/stdc++.h> using namespace std; namespace red{ #define int long long #define ls(p) (p<<1) #define rs(p) (p<<1|1) #define mid ((l+r)>>1) #define lowbit(i) ((i)&(-i)) inline int read() { int x=0;char f=0,ch; for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar()); if(ch=='-') f=1,ch=getchar(); while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();} return f?-x:x; } const int N=2010,inf=1e18; int n,a,b,c,tot; int w[N]; priority_queue<int,vector<int>,greater<int> > q1,q2; inline void main() { n=read(),a=read(),b=read(),c=read(); for(int i=1;i<=n;++i) w[i]=read(); for(int i=1;i<=n;++i) w[i]=read()-w[i]; for(int val,i=1;i<=n;++i) { if(w[i]>0) { for(int k=1;k<=w[i];++k) { val=a*i; if(!q2.empty()) { val=min(val,q2.top()+c*i); q2.pop(); } tot+=val; q1.push(-val-c*i); } } else { for(int k=1;k<=-w[i];++k) { val=b*(n-i+1); if(!q1.empty()) { val=min(val,q1.top()+c*i); q1.pop(); } tot+=val; q2.push(-val-c*i); } } } printf("%lld\n",tot); } } signed main() { red::main(); return 0; } /* 12 4 5 2 3 4 5 8 */