记录编号 |
393171 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[HAOI 2010]订货 |
最终得分 |
100 |
用户昵称 |
HeHe |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.006 s |
提交时间 |
2017-04-10 08:08:42 |
内存使用 |
0.32 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
const int MAXN = 100, INF = 0x7fffffff;
const inline int in(void){
char tmp = getchar();
int res = 0;
while(!isdigit(tmp))tmp = getchar();
while(isdigit(tmp))
res = (res + (res << 2) << 1) + (tmp ^ 48),
tmp = getchar();
return res;
}
struct EDGE{
int fr, to, ne;
int cap, w;
EDGE(){;}
EDGE(int a, int b, int c, int d, int e){
fr = a, to = b, ne = c;
cap = d, w = e;
}
};
const inline void add_edge(int fr, int to, int cap, int w);
bool SPFA(void);
int get_cost(void);
vector<EDGE> edge;
int head[MAXN];
int pre[MAXN];
int dis[MAXN];
queue<int> que;
bool inq[MAXN];
int S, T, ans;
int n, m, s;
int u[MAXN], d[MAXN];
int main(){
#ifndef LOCAL
freopen("order.in", "r", stdin);
freopen("order.out", "w", stdout);
#endif
memset(head, 0xff, sizeof(head));
n = in(), m = in(), s = in();
for(int i = 1; i <= n; ++i)u[i] = in();
for(int i = 1; i <= n; ++i)d[i] = in();
S = 0, T = n + 1;
for(int i = 1; i <= n; ++i){
add_edge(0, i, INF, d[i]);
add_edge(i, T, u[i], 0);
}
for(int i = 1; i < n; ++i){
add_edge(i, i + 1, s, m);
}
while(SPFA()){
ans += get_cost();
}
printf("%d", ans);
return 0;
}
const inline void add_edge(int fr, int to, int cap, int w){
edge.push_back(EDGE(fr, to, head[fr], cap, w)), head[fr] = edge.size() - 1;
edge.push_back(EDGE(to, fr, head[to], 0, -w)), head[to] = edge.size() - 1;
}
bool SPFA(void){
memset(inq, 0, sizeof(inq));
memset(dis, 0x7f, sizeof(dis));
memset(pre, 0xff, sizeof(pre));
while(!que.empty())que.pop();
que.push(S);
inq[S] = true;
dis[S] = 0;
int now, to;
while(!que.empty()){
now = que.front();
que.pop();
inq[now] = false;
for(int i = head[now]; i != -1; i = edge[i].ne){
to = edge[i].to;
if(edge[i].cap <= 0 || dis[now] + edge[i].w >= dis[to])continue;
dis[to] = dis[now] + edge[i].w;
pre[to] = i;
if(inq[to])continue;
que.push(to);
inq[to] = true;
}
}
if(dis[T] == 0x7f7f7f7f)return false;
return true;
}
int get_cost(void){
int now = pre[T], min_flow = INF;
while(now != -1){
min_flow = min(min_flow, edge[now].cap);
now = pre[edge[now].fr];
}
now = pre[T];
while(now != -1){
edge[now].cap -= min_flow;
edge[now ^ 1].cap += min_flow;
now = pre[edge[now].fr];
}
return dis[T] * min_flow;
}