1090: MTM

Time Limit:3000/1000 MS (Java/Others)   Memory Limit:163840/131072 KB (Java/Others)
Total Submissions:127   Accepted:19

[Submit][Status][Discuss]

Description

MTM is not only a good ACMer but also a good teacher. There are n" role="presentation">n

students in MTM’s class. Every student has two skills, each measured as a number:ai" role="presentation">ai – the programming skill andbi" role="presentation">bi

– the math skill.

Both ACM competition and Math
competition will be held soon. So MTM decides to compose two teams to
take part in these competitions. Because of the limitation of the number
of student, MTM has to select p" role="presentation">p

students to take part in the ACM competition ands" role="presentation">s

students to take part in the Math competition. A student can't be a member of both teams.

MTM considers that his expected
result is equal to the sum of two values: the ACM team strength and the
Math team strength. The strength of each team is the sum of skills of
its members in the corresponding area.

Help MTM to compose two teams to maximize his expected result.

Input

The input test file will contain multiple test cases. The first line of each input contains three positive integer numbers n" role="presentation">n

, p" role="presentation">p and s" role="presentation">s (2 ≤ n ≤ 500" role="presentation">2≤n≤500, p + s ≤ n" role="presentation">p+s≤n) --- the number of students, the size of the ACM team and the size of the Math team.

The second line contains n" role="presentation">n positive integers a1, a2, …, an" role="presentation">a1,a2,…,an (1 ≤ ai ≤ 500" role="presentation">1≤ai≤500), where ai" role="presentation">ai is the programming skill of the i" role="presentation">i-th student.

The third line containsn" role="presentation">n positive integersb1, b2, …, bn" role="presentation">b1,b2,…,bn (1 ≤ bi ≤ 500" role="presentation">1≤bi≤500), wherebi" role="presentation">bi is the math skill of thei" role="presentation">i

-th student.

Output

In
the first line, print the maximum strength of MTM’s expected result. In
the second line, print p numbers — the members of the ACM team. In the
third line, print s numbers — the members of the Math team.

The students are numbered from 1" role="presentation">1

ton" role="presentation">n

as they are given in the input. All numbers printed in the second and in the third lines should be distinct and should be printed in ascending order.

Sample Input

5 2 2
1 3 4 5 2
5 3 2 1 4 4 2 2
10 8 8 3
10 7 9 4 5 3 1
5 2 5 1 7
6 3 1 6 3

Sample Output

18
3 4
1 5
31
1 2
3 4
23
1 3 5
4
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define inf 0x7fffffff
#define mod 10000
#define met(a,b) memset(a,b,sizeof a)
typedef long long ll;
using namespace std;
const int N = +;
const int M = ;
set<int>ac,ma;
int n,p,s;
int acm[N],math[N];
struct Edge {
int from, to, cap, flow;
int cost;
};
inline int Min(int aa,int bb)
{
return aa<bb?aa:bb;
}
struct MCMF {
int n, m, s, t;
vector<Edge> edges;
vector<int> G[N];
int inq[N]; // 是否在队列中
int d[N]; // Bellman-Ford
int p[N]; // 上一条弧
int a[N]; // 可改进量
void init(int n) {
this->n = n;
for(int i = ; i < n; i++) G[i].clear();
edges.clear();
} void addedge(int from, int to, int cap, int cost) {
edges.push_back((Edge){from, to, cap, , cost});
edges.push_back((Edge){to, from, , , -cost});
m = edges.size();
G[from].push_back(m-);
G[to].push_back(m-);
} bool BellmanFord(int s, int t, int& flow,int& cost) {
for(int i = ; i < n; i++) d[i] = inf;
memset(inq, , sizeof(inq));
d[s] = ; inq[s] = ; p[s] = ; a[s] = inf; queue<int> Q;
Q.push(s);
while(!Q.empty()) {
int u = Q.front(); Q.pop();
inq[u] = ;
int l=G[u].size();
for(int i = ; i < l; i++) {
Edge& e = edges[G[u][i]];
if(e.cap > e.flow && d[e.to] > d[u] + e.cost) {
d[e.to] = d[u] + e.cost;
p[e.to] = G[u][i];
a[e.to] = Min(a[u], e.cap - e.flow);
if(!inq[e.to]) { Q.push(e.to); inq[e.to] = ; }
}
}
}
if(d[t] == inf) return false;
cost += d[t]*a[t];
int u = t;
while(u != s) {
edges[p[u]].flow += a[t];
edges[p[u]^].flow -= a[t];
u = edges[p[u]].from;
}
return true;
}
// 需要保证初始网络中没有负权圈
void Mincost(int s, int t) {
int cost = ;
int flow=;
while(BellmanFord(s, t,flow, cost));
printf("%d\n",-cost);
}
}g;
int main() {
int k;
while(~scanf("%d%d%d",&n,&p,&s) ) {
g.init(n+);
ac.clear();ma.clear();
for(int i=;i<=n;i++)scanf("%d",&acm[i]);
for(int i=;i<=n;i++)scanf("%d",&math[i]);
for(int i=;i<=n;i++){
g.addedge(,i,,);
g.addedge(i,n+,,-acm[i]);
g.addedge(i,n+,,-math[i]);
}
g.addedge(n+,n+,p,);g.addedge(n+,n+,s,);
int ans=;
g.Mincost(,n+); for(int i=;i<g.m;i++){
Edge temp=g.edges[i];
if(temp.to==n+&&temp.flow==) {
ac.insert(temp.from);
}
else if(temp.to==n+&&temp.flow==) {
ma.insert(temp.from);
}
}
bool f=false;
for(int x:ac){
if (f==false){
printf("%d",x);
f=true;
}
else
printf(" %d",x);
}
printf("\n");
f=false;
for(int x:ma){
if (f==false){
printf("%d",x);
f=true;
}
else
printf(" %d",x);
}
printf("\n");
}
return ;
}

1090: MTM (费用流)的更多相关文章

  1. hdu-5988 Coding Contest(费用流)

    题目链接: Coding Contest Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Ot ...

  2. POJ2195 Going Home[费用流|二分图最大权匹配]

    Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22088   Accepted: 11155 Desc ...

  3. BZOJ3130: [Sdoi2013]费用流[最大流 实数二分]

    3130: [Sdoi2013]费用流 Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 960  Solved: 5 ...

  4. 洛谷 1004 dp或最大费用流

    思路: dp方法: 设dp[i][j][k][l]为两条没有交叉的路径分别走到(i,j)和(k,l)处最大价值. 则转移方程为 dp[i][j][k][l]=max(dp[i-1][j][k-1][l ...

  5. Codeforces 730I [费用流]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给两行n个数,要求从第一行选取a个数,第二行选取b个数使得这些数加起来和最大. 限制条件是第一行选取了某个数的条件下,第二行不能选取对应位置的数. ...

  6. zkw费用流+当前弧优化

    zkw费用流+当前弧优化 var o,v:..] of boolean; f,s,d,dis:..] of longint; next,p,c,w:..] of longint; i,j,k,l,y, ...

  7. 【BZOJ-4213】贪吃蛇 有上下界的费用流

    4213: 贪吃蛇 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 58  Solved: 24[Submit][Status][Discuss] Desc ...

  8. 【BZOJ-3638&3272&3267&3502】k-Maximum Subsequence Sum 费用流构图 + 线段树手动增广

    3638: Cf172 k-Maximum Subsequence Sum Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 174  Solved: 9 ...

  9. [bzoj4514]数字配对[费用流]

    今年SDOI的题,看到他们在做,看到过了一百多个人,然后就被虐惨啦... 果然考试的时候还是打不了高端算法,调了...几天 默默地yy了一个费用流构图: 源连所有点,配对的点连啊,所有点连汇... 后 ...

随机推荐

  1. MFC 相关类、函数

    timeSetEvent()函数 CRectTracker类的使用 SetLocalTime设置本地时间 AdjustTokenPrivileges启用权限

  2. 【CF edu 30 C. Strange Game On Matrix】

    time limit per test 1 second memory limit per test  256 megabytes input standard input output standa ...

  3. YUI Compressor是如何压缩JS代码的?

    YUI Compressor 压缩 JavaScript 的内容包括: 移除注释 移除额外的空格 细微优化 标识符替换(Identifier Replacement) YUI Compressor 包 ...

  4. 活泼的CSS 3动态气泡按钮制作

    这一次,我们正在创造一个有用的设置与对CSS3的多重背景和动画的力量动画按钮.通过此按钮包,您可以很容易地变成一个动画按钮,在您的网页上的任何链接只是指定一个类名.没有必要JavaScript.四色主 ...

  5. MySQL使用笔记(三)表的操作

    By francis_hao    Dec 11,2016 表的操作 表的操作有创建表.查看表.删除表和修改表 创建表 创建表之前要在某个数据库中. mysql> create table ta ...

  6. git使用笔记(二)分支与合并

    By francis_hao    Nov 18,2016 查看分支,* 表示当前所在分支 $ git branch 查看分支和最后一次提交记录 $ git branch -v 新建分支 $ git ...

  7. 百度vue服务端渲染(ssr)有感

    前端各种框架工具层次不穷,日新月异,越学越混乱了快 知乎上看到了一段回复,豁然开朗的感觉. Web 2.0时代最大的思想革命本质不是前后端分离,而是把网页当作独立的应用程序(app).前后端分离只是实 ...

  8. React 开发常见报错解决方法

    1. 使用 redux 的异步 action 时浏览器报错: Error: Actions must be plain objects. Use custom middleware for async ...

  9. Bzoj3441 乌鸦喝水

    Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 258  Solved: 97 Description [题目背景]     一只乌鸦在自娱自乐,它在面 ...

  10. jQuery获取表格隐藏域与ajax请求数据结合显示详情

    0.表格样式