# 冲刺NOI2017 (22) 养猫 （线性规划方程转网络流）

## 题解

x11100000x21111000x31111110x41111110x50011110x60000110+a1b1+a2b2+a3b3=======mxmnmxmnmxmn0

.

'''''''x11010000x21000100x31000001x41000001x50010001x60000101+a1a1b1+b1+a2a2b2+b2+a3a3b3+b3=======mxmnmxmxmnmnmxmxmnmnmxmn

## 代码

#include <cstdio>
#include <iostream>
//#include <ctime>
#include <queue>
using namespace std;

const int maxn=int(2e3)+111;
int n,k,minc,mins;
int c[maxn], s[maxn];

scanf("%d%d%d%d",&n,&k,&minc,&mins);
register int i;
for(i=1;i<=n;++i) scanf("%d",&c[i]);
for(i=1;i<=n;++i) scanf("%d",&s[i]);
return;
}

const int maxe=int(2e6)+111, inf=int(1e9)+7;
const long long INF=1ll<<60;
int S,T;
int id[maxn];

struct Edge {
int to,cap,cost,next;
Edge() {}
Edge(int y,int ca,int co,int nx):to(y),cap(ca),cost(co),next(nx) {}
}eage[maxe<<1];

inline void Add_eage(int x,int y,int cap,int cost) {
}

void Build() {
int mx=k-minc,mn=mins,num=(n-k+1)<<1;
S=0, T=num+2;
register int i;
for(i=S;i<=T;++i)

//Constant on rhs
for(i=2;i<=num;++i) {
}
//Variable on lhs
for(i=1;i<=num+1;i+=2) {
}
//Keypoint on lhs
for(i=1;i<=n;++i) {
id[i]=tot-1;
}

}

long long dis[maxn];
bool used[maxn], vis[maxn];
queue<int> que;

bool spfa() {
while(que.size()) que.pop();
register int i,u,v;
for(i=0;i<maxn;++i) {
dis[i]=INF;
used[i]=false, vis[i]=false;
}

que.push(S);
used[S]=true;
dis[S]=0;

while(que.size()) {
u=que.front(); que.pop();
used[u]=false;
v=eage[i].to;
dis[v]=dis[u]+eage[i].cost;
if(!used[v]) {used[v]=true; que.push(v);}
}
}
return dis[T]<INF;
}

long long ans=0;
int dfs(int u,int flow) {
if(u==T || !flow) {
ans+=dis[u]*flow;
return flow;
}
vis[u]=true;
int ret=0;
register int i,v;
for(i=head[u];~i;i=eage[i].next) if(eage[i].cap && !vis[eage[i].to] && dis[eage[i].to]==dis[u]+eage[i].cost) {
v=eage[i].to;
int newf=dfs(v,min(flow,eage[i].cap));
eage[i].cap-=newf;
eage[i^1].cap+=newf;
ret+=newf;
flow-=newf;
if(!flow) break;
}
if(!ret) dis[u]=-1;
return ret;
}

int MCMF() {
int res=0; ans=0;
while(spfa()) res+=dfs(S,inf);
ans=-ans;
return res;
}

int main() {
#ifndef ONLINE_JUDGE
freopen("cat.in","r",stdin);
freopen("cat.out","w",stdout);
#endif
//  double t1=clock();

Build();
MCMF();

register int i;
for(i=1;i<=n;++i) ans+=c[i];

cout<<ans<<endl;
for(i=1;i<=n;++i) {
if(eage[id[i]].cap) putchar('E');
else putchar('S');
}
putchar('\n');

//  printf("%.3lfsec\n",(clock()-t1)/CLOCKS_PER_SEC);
return 0;
}