```cpp
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2005, M = 2e6 + 5, inf = 1e18, mod = 2000 * 20;
int n, r[N], p, t1, f, t2, s, fir[N << 1], son[M], eage[M], w[M], nxt[M], tot = 1, q[N * 20], d[N], x, flow[N], h, t, pre[N], ans;
bool vis[N];
inline void add(int x, int y, int z, int flow){
nxt[++tot] = fir[x];
fir[x] = tot;
son[tot] = y;
eage[tot] = flow;
w[tot] = z;
}
inline void Add(int x, int y, int z, int flow){
add(x, y, z, flow);
add(y, x, -z, 0);
}
inline void build_graph(){
for(int i = 1; i <= n; i++) Add(n * 2 + 1, i + n, 0, r[i]);
for(int i = 1; i < n; i++) Add(i + n, i + n + 1, 0, inf);
for(int i = 1; i <= n; i++) Add(i, n * 2 + 2, 0, r[i]);
for(int i = 1; i <= n - t1; i++) Add(i + n, i + t1, f, inf);
for(int i = 1; i <= n - t2; i++) Add(i + n, i + t2, s, inf);
for(int i = 1; i <= n; i++) Add(n * 2 + 1, i, p, inf);
}
inline void calc(int &x){
x++;
if(x >= mod) x -= mod;
}
inline bool spfa(){
for(int i = 1; i <= n; i++) d[i] = inf;
for(int i = 1; i <= n; i++) vis[i] = 0;
q[t = 1] = n - 1, h = 0, d[n - 1] = 0, vis[n - 1] = 1, flow[n - 1] = inf;
while(h != t){
calc(h);
x = q[h];
vis[x] = 0;
for(int i = fir[x]; i ; i = nxt[i]){
if(eage[i]){
if(d[son[i]] > d[x] + w[i]){
d[son[i]] = d[x] + w[i];
flow[son[i]] = min(flow[x], eage[i]);
pre[son[i]] = i;
if(!vis[son[i]]){
calc(t);
vis[son[i]] = 1;
q[t] = son[i];
}
}
}
}
}
return d[n] < inf;
}
inline void upd(){
x = n;
ans += flow[x] * d[x];
while(x != n - 1){
x = pre[x];
eage[x] -= flow[n];
eage[x ^ 1] += flow[n];
x = son[x ^ 1];
}
}
signed main(){
// freopen("P1251_2.in", "r", stdin);
// freopen("code.out", "w", stdout);
scanf("%lld", &n);
for(int i = 1; i <= n; i++) scanf("%lld", &r[i]);
scanf("%lld%lld%lld%lld%lld", &p, &t1, &f, &t2, &s);
build_graph();
n = n * 2 + 2;
while(spfa()){
upd();
}
printf("%lld", ans);
return 0;
}
```
by huangrenheluogu @ 2023-11-27 15:47:36
好好好,萌新是吧
by Kdlyh @ 2023-11-27 16:32:59
@[Kdlyh](/user/77076) 就是网络流萌新,大佬帮帮蒟蒻。
by huangrenheluogu @ 2023-11-27 17:40:56
@[huangrenheluogu](/user/461359) 爱莫能助。。
by Kdlyh @ 2023-11-27 17:52:18
数组开小了,结此贴。
by huangrenheluogu @ 2023-11-28 20:32:16