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. linux管理(二)---网络使用情况的监控

    我们经常在监控服务器或者排查程序性能瓶颈时需要知道  网络带宽的使用情况,看看带宽是不是瓶颈. linux系统中监控网络的工具和命令很多. 但其实主要分2种,一种是实时监控带宽情况(速度如何),一种是 ...

  2. POJ3189:Steady Cow Assignment(二分+二分图多重匹配)

    Steady Cow Assignment Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7482   Accepted: ...

  3. HDU 1394 Minimum Inversion Number(树状数组/归并排序实现

    Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  4. Restful 接口权限控制

    前言 有人说,每个人都是平等的: 也有人说,人生来就是不平等的: 在人类社会中,并没有绝对的公平, 一件事,并不是所有人都能去做: 一样物,并不是所有人都能够拥有. 每个人都有自己的角色,每种角色都有 ...

  5. jsp中的一些细节和注意要点。。。。。简记

    一: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en&quo ...

  6. Nginx的client_header_buffer_size和large_client_header_buffers学习

    之前看到有人写的一篇关于nginx配置中large_client_header_buffers的问题排查的文章,其中提到: large_client_header_buffers 虽然也可以在serv ...

  7. L2-001. 紧急救援---(Dijkstra,记录路径)

    https://www.patest.cn/contests/gplt/L2-001 L2-001. 紧急救援 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 ...

  8. php2go - Go 实现 PHP 常用内置函数

    [转]http://www.syyong.com/Go/php2go-Use-Golang-to-implement-PHP-s-common-built-in-functions.html 使用Go ...

  9. Eclipse Tomcat部署项目没有加载新加的静态资源文件

    额,一直用MyEclipse,后来用Eclipse时,启动项目后去Tomcat webapps找对应文件夹,发现没有,才知道Eclipse 默认不往本地Tomcat部署. 1.eclipse不像MyE ...

  10. 利用ES6的Promise.all实现至少请求多长时间

    1.背景 我们都知道ajax请求可以加个timeout,就是最多请求多少时间,如果超过这个时间直接就报错. 这个是最多请求多长时间,我现在要做的是,最少要请求多长时间,然后才能执行后续的逻辑. 比如, ...