There are n students at Berland State University. Every student has two skills, each measured as a number: ai — the programming skill and bi — the sports skill.
It is announced that an Olympiad in programming and sports will be held soon. That’s why Berland State University should choose two teams: one to take part in the programming track and one to take part in the sports track.
There should be exactly p students in the programming team and exactly s students in the sports team. A student can’t be a member of both teams.
The university management considers that the strength of the university on the Olympiad is equal to the sum of two values: the programming team strength and the sports team strength. The strength of a team is the sum of skills of its members in the corresponding area, so the strength of the programming team is the sum of all ai and the strength of the sports team is the sum of all bi over corresponding team members.
Help Berland State University to compose two teams to maximize the total strength of the university on the Olympiad.
Input
The first line contains three positive integer numbers n, p and s (2 ≤ n ≤ 3000, p + s ≤ n) — the number of students, the size of the programming team and the size of the sports team.
The second line contains n positive integers a1, a2, …, an (1 ≤ ai ≤ 3000), where ai is the programming skill of the i-th student.
The third line contains n positive integers b1, b2, …, bn (1 ≤ bi ≤ 3000), where bi is the sports skill of the i-th student.
Output
In the first line, print the the maximum strength of the university on the Olympiad. In the second line, print p numbers — the members of the programming team. In the third line, print s numbers — the members of the sports team.
The students are numbered from 1 to n as they are given in the input. All numbers printed in the second and in the third lines should be distinct and can be printed in arbitrary order.
If there are multiple solutions, print any of them.
Examples
inputCopy
5 2 2
1 3 4 5 2
5 3 2 1 4
outputCopy
18
3 4
1 5
inputCopy
4 2 2
10 8 8 3
10 7 9 4
outputCopy
31
1 2
3 4
inputCopy
5 3 1
5 2 5 1 7
6 3 1 6 3
outputCopy
23
1 3 5
4
很明显的费用流。
建立四个虚拟节点,源点S,汇点T,PP,PS,保证选择的人数一定满足要求。然后最大费用流求出最大价值。
最后在残量网络上面找到每条路的流。
用容器存一下,最后输出即可。
AC代码:
#pragma GCC optimize(2)
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int inf=0x3f3f3f3f;
const int N=3e3+10,M=1e6+10;
int n,np,ns,s,t,pp,ps,d[N],st[N],vis[N],a[N],b[N],res;
int head[N],nex[M],to[M],w[M],flow[M],tot=1;
vector<int> v1,v2;
inline void ade(int a,int b,int c,int d){
to[++tot]=b; nex[tot]=head[a]; w[tot]=d; flow[tot]=c; head[a]=tot;
}
inline void add(int a,int b,int c,int d){ade(a,b,c,d); ade(b,a,0,-d);}
inline int spfa(){
queue<int> q; q.push(s); memset(st,0,sizeof st);
memset(d,-inf,sizeof d); d[s]=0; vis[s]=1;
while(q.size()){
int u=q.front(); q.pop(); vis[u]=0;
for(int i=head[u];i;i=nex[i]){
if(flow[i]&&d[to[i]]<d[u]+w[i]){
d[to[i]]=d[u]+w[i];
if(!vis[to[i]]) q.push(to[i]),vis[to[i]]=1;
}
}
}
return d[t]>=0;
}
int dfs(int x,int f){
if(x==t) return res+=d[t]*f,f;
st[x]=1; int fl=0;
for(int i=head[x];i&&f;i=nex[i]){
if(flow[i]&&!st[to[i]]&&d[to[i]]==d[x]+w[i]){
int mi=dfs(to[i],min(f,flow[i]));
flow[i]-=mi,flow[i^1]+=mi,fl+=mi,f-=mi;
}
}
return fl;
}
signed main(){
cin>>n>>np>>ns; pp=n+1,ps=pp+1,t=ps+1;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
for(int i=1;i<=n;i++){
add(s,i,1,0); add(i,pp,1,a[i]); add(i,ps,1,b[i]);
}
add(pp,t,np,0); add(ps,t,ns,0);
while(spfa()) dfs(s,inf);
cout<<res<<endl;
for(int i=1;i<=n;i++){
for(int j=head[i];j;j=nex[j]){
if(!flow[j^1]) continue;
if(to[j]==pp) v1.push_back(i);
if(to[j]==ps) v2.push_back(i);
}
}
for(int i=0;i<v1.size();i++) cout<<v1[i]<<' ';puts("");
for(int i=0;i<v2.size();i++) cout<<v2[i]<<' ';puts("");
return 0;
}