和餐巾计划一模一样,题解:传送门
就是这道题的x天,需要+1.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 2010
#define M 6010
#define inf 0x3f3f3f3f
inline 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;
}
int n,t1,t2,P,c1,c2,h[N],num=1,T=2001,dis[N],ans=0,path[N];
bool inq[N];
struct edge{
int to,next,w,c;
}data[M<<1];
inline void add(int x,int y,int w,int c){
data[++num].to=y;data[num].next=h[x];h[x]=num;data[num].w=w;data[num].c=c;
data[++num].to=x;data[num].next=h[y];h[y]=num;data[num].w=0;data[num].c=-c;
}
inline bool spfa(){
queue<int>q;memset(dis,inf,sizeof(dis));memset(path,0,sizeof(path));
q.push(0);inq[0]=1;dis[0]=0;
while(!q.empty()){
int x=q.front();q.pop();inq[x]=0;
for(int i=h[x];i;i=data[i].next){
int y=data[i].to;if(!data[i].w) continue;
if(dis[x]+data[i].c<dis[y]){
dis[y]=dis[x]+data[i].c;path[y]=i;
if(!inq[y]) q.push(y),inq[y]=1;
}
}
}return path[T];
}
int main(){
// freopen("a.in","r",stdin);
n=read();t1=read();t2=read();P=read();c1=read();c2=read();
for(int i=1;i<=n;++i){
int x=read();add(0,i,x,0);add(i+n,T,x,0);
if(i+t1+1<=n) add(i,i+t1+1+n,inf,c1);
if(i+t2+1<=n) add(i,i+t2+1+n,inf,c2);
if(i+1<=n) add(i,i+1,inf,0);add(0,i+n,inf,P);
}while(spfa()){
int low=inf,now=T;
while(path[now]) low=min(low,data[path[now]].w),now=data[path[now]^1].to;
ans+=low*dis[T];now=T;
while(path[now]) data[path[now]].w-=low,data[path[now]^1].w+=low,now=data[path[now]^1].to;
}printf("%d\n",ans);
return 0;
}