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

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

Sample Output

  1. 18
  2. 3 4
  3. 1 5
  4. 31
  5. 1 2
  6. 3 4
  7. 23
  8. 1 3 5
  9. 4
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <algorithm>
  6. #include <cmath>
  7. #include <time.h>
  8. #include <string>
  9. #include <map>
  10. #include <stack>
  11. #include <vector>
  12. #include <set>
  13. #include <queue>
  14. #define inf 0x7fffffff
  15. #define mod 10000
  16. #define met(a,b) memset(a,b,sizeof a)
  17. typedef long long ll;
  18. using namespace std;
  19. const int N = +;
  20. const int M = ;
  21. set<int>ac,ma;
  22. int n,p,s;
  23. int acm[N],math[N];
  24. struct Edge {
  25. int from, to, cap, flow;
  26. int cost;
  27. };
  28. inline int Min(int aa,int bb)
  29. {
  30. return aa<bb?aa:bb;
  31. }
  32. struct MCMF {
  33. int n, m, s, t;
  34. vector<Edge> edges;
  35. vector<int> G[N];
  36. int inq[N]; // 是否在队列中
  37. int d[N]; // Bellman-Ford
  38. int p[N]; // 上一条弧
  39. int a[N]; // 可改进量
  40. void init(int n) {
  41. this->n = n;
  42. for(int i = ; i < n; i++) G[i].clear();
  43. edges.clear();
  44. }
  45.  
  46. void addedge(int from, int to, int cap, int cost) {
  47. edges.push_back((Edge){from, to, cap, , cost});
  48. edges.push_back((Edge){to, from, , , -cost});
  49. m = edges.size();
  50. G[from].push_back(m-);
  51. G[to].push_back(m-);
  52. }
  53.  
  54. bool BellmanFord(int s, int t, int& flow,int& cost) {
  55. for(int i = ; i < n; i++) d[i] = inf;
  56. memset(inq, , sizeof(inq));
  57. d[s] = ; inq[s] = ; p[s] = ; a[s] = inf;
  58.  
  59. queue<int> Q;
  60. Q.push(s);
  61. while(!Q.empty()) {
  62. int u = Q.front(); Q.pop();
  63. inq[u] = ;
  64. int l=G[u].size();
  65. for(int i = ; i < l; i++) {
  66. Edge& e = edges[G[u][i]];
  67. if(e.cap > e.flow && d[e.to] > d[u] + e.cost) {
  68. d[e.to] = d[u] + e.cost;
  69. p[e.to] = G[u][i];
  70. a[e.to] = Min(a[u], e.cap - e.flow);
  71. if(!inq[e.to]) { Q.push(e.to); inq[e.to] = ; }
  72. }
  73. }
  74. }
  75. if(d[t] == inf) return false;
  76. cost += d[t]*a[t];
  77. int u = t;
  78. while(u != s) {
  79. edges[p[u]].flow += a[t];
  80. edges[p[u]^].flow -= a[t];
  81. u = edges[p[u]].from;
  82. }
  83. return true;
  84. }
  85. // 需要保证初始网络中没有负权圈
  86. void Mincost(int s, int t) {
  87. int cost = ;
  88. int flow=;
  89. while(BellmanFord(s, t,flow, cost));
  90. printf("%d\n",-cost);
  91. }
  92. }g;
  93. int main() {
  94. int k;
  95. while(~scanf("%d%d%d",&n,&p,&s) ) {
  96. g.init(n+);
  97. ac.clear();ma.clear();
  98. for(int i=;i<=n;i++)scanf("%d",&acm[i]);
  99. for(int i=;i<=n;i++)scanf("%d",&math[i]);
  100. for(int i=;i<=n;i++){
  101. g.addedge(,i,,);
  102. g.addedge(i,n+,,-acm[i]);
  103. g.addedge(i,n+,,-math[i]);
  104. }
  105. g.addedge(n+,n+,p,);g.addedge(n+,n+,s,);
  106. int ans=;
  107. g.Mincost(,n+);
  108.  
  109. for(int i=;i<g.m;i++){
  110. Edge temp=g.edges[i];
  111. if(temp.to==n+&&temp.flow==) {
  112. ac.insert(temp.from);
  113. }
  114. else if(temp.to==n+&&temp.flow==) {
  115. ma.insert(temp.from);
  116. }
  117. }
  118. bool f=false;
  119. for(int x:ac){
  120. if (f==false){
  121. printf("%d",x);
  122. f=true;
  123. }
  124. else
  125. printf(" %d",x);
  126. }
  127. printf("\n");
  128. f=false;
  129. for(int x:ma){
  130. if (f==false){
  131. printf("%d",x);
  132. f=true;
  133. }
  134. else
  135. printf(" %d",x);
  136. }
  137. printf("\n");
  138. }
  139. return ;
  140. }

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. Seajs的用法

    以前经常听到Seajs,但是没深入了解过,不清楚到底是用做哪个方面,后来调组到M站做开发,发现项目用到了Seajs,便去了解下 SeaJS是一个遵循CMD规范的JavaScript模块加载框架,可以实 ...

  2. yaf学习网站

    http://www.01happy.com/php-yaf-ext-business/

  3. Dilworth定理证明

    命题:偏序集能划分成的最少的全序集的个数与最大反链的元素个数相等. (离散数学结构第六版课本P245:把一个偏序集划分成具有全序的子集所需要的最少子集个数与元素在偏序下都是不可比的最大集合的基数之间有 ...

  4. 简单瞎搞题(bitset的操作)

    链接:https://www.nowcoder.com/acm/contest/132/C来源:牛客网 题目 一共有 n个数,第 i 个数是 xi  xi 可以取 [li , ri] 中任意的一个值. ...

  5. JavaScript 被忽视的细节

    语句/表达式 换个角度理解语句(statemaents)和表达式(expressions):表达式不会改变程序的运行状态,而语句会.还有一种叫做表达式语句,可以理解为表达式和语句的交集,如({a:1} ...

  6. 线程 ManualResetEvent 类

    Reset(): 当一个线程开始一个活动(此活动必须完成后,其他线程才能开始)时, 它调用 Reset 以将 ManualResetEvent 置于非终止状态.此线程可被视为控制 ManualRese ...

  7. Web项目中加载Spring配置的常用方法

    1.web.xml中添加配置 <web-app>      <context-param>         <param-name>contextConfigLoc ...

  8. Spring 对象的声明与注入

    1.怎么把一个对象该过过交给Spring管理? 1)通过xml中配置<bean>节点来声明 2)通过Spring注解来声明,如:@Service.@Repository.@Componen ...

  9. 【Atcoder】ARC082 E - ConvexScore

    [算法]计算几何 [题意]给定平面直角坐标系上的若干个点,任意选点连成凸多边形,凸多边形的价值定义为2^(n-|S|),其中n为凸多边形内部点数(含边界),|S|为顶点数,求总价值.n<=10^ ...

  10. [object-c 2.0 程序设计]object-c review (一)

    // // main.m // cmdTry // // Created by Calos Chen on 2017/8/21. // Copyright © 2017年 Calos Chen. Al ...