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. 【BZOJ 3165】 [Heoi2013]Segment 李超线段树

    所谓李超线段树就是解决此题一类的问题(线段覆盖查询点最大(小)),把原本计算几何的题目变成了简单的线段树,巧妙地结合了线段树的标记永久化与标记下传,在不考虑精度误差的影响下,打法应该是这样的. #in ...

  2. [ST表/贪心] NOI2010 超级钢琴

    [NOI2010]超级钢琴 题目描述 小Z是一个小有名气的钢琴家,最近C博士送给了小Z一架超级钢琴,小Z希望能够用这架钢琴创作出世界上最美妙的音乐. 这架超级钢琴可以弹奏出n个音符,编号为1至n.第i ...

  3. AngularJs开发——控制器间的通信

    AngularJs开发——控制器间的通信 指令与控制器之间通信,无非是以下几种方法: 基于scope继承的方式 基于event传播的方式 service的方式 基于scope继承的方式 最简单的让控制 ...

  4. IDEA 用maven创建web项目编译时不能发布resources中的文件

    1.在pom.xml加入 <build> <resources> <resource> <directory>${basedir}/src/main/j ...

  5. Xamarin+vs2010部署错误:error MSB6004: 指定的任务可执行文件位置\sdk\\tools\zipalign.exe”无效

    好不容易配好了Xamarin和vs2010,也搞好了GenyMotion的虚拟机配置,开始调试的时候又报出了这样的错误: error MSB6004: 指定的任务可执行文件位置"C:\Use ...

  6. hive向表格中插入数据并分析语句

    1,---导入mds_imei_month_info ; //最大的动态分区表 set hive.support.concurrency=false; //是否支持并发 ; //each mapper ...

  7. 【BZOJ3132】上帝造题的七分钟 [树状数组]

    上帝造题的七分钟 Time Limit: 20 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description “第一分钟,X说,要有矩阵 ...

  8. 【BZOJ】1579: [Usaco2009 Feb]Revamping Trails 道路升级

    [算法]分层图最短路 [题解] 考虑k层一模一样的图,然后每个夹层都在每条边的位置新加从上一层跨越到下一层的边权为0的边,这样至多选择k条边置为0. 然后考虑方便的写法. SPFA 第一次SPFA计算 ...

  9. spoj p104 Matrix-Tree定理

    这个问题就是经典的生成树记数问题,题目为spoj p104 highway. 首先我们引入Matrix-Tree定理,由kirchhoff证明,定理的概述为,对于图G,我们定义若干个矩阵, D[G], ...

  10. python3 匿名函数,map/reduce/filter等函数结合应用

    匿名函数就是不需要显式的指定函数 # 平方函数 def func1(x): return x**2 print(func1) # 平方函数匿名函数写法 func2=lambda x:x**2 prin ...