#include #include #include #include #include #include using namespace std; typedef long long LL; const int INF=1<<30; const int maxn=210; const int maxd=maxn*2; const int maxe=maxn*10*maxn+maxn*8; LL read(){ char ch=getchar(); while((ch<'0'||ch>'9')&&ch!='-') ch=getchar(); LL x,tag; if(ch=='-') x=0,tag=-1; else x=ch-'0',tag=1; ch=getchar(); while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*tag; } void writeln(LL x){ if(!x) putchar('0'); else{ if(x<0) putchar('-'),x=abs(x); LL ch[50],l=0; while(x) ch[l++]=x%10,x/=10; while(l) putchar(ch[--l]+'0'); } putchar('\n'); } struct edge{ int from,to,next,cap,flow,cost; }e[maxe]; int s,t,e_num=1,num,head[maxd],q[maxd],a[maxd],fa[maxd],d[maxd]; bool vis[maxd]; void add_edge(int u,int v,int c,int w){ e[++e_num]=(edge){u,v,head[u],c,0,w}; head[u]=e_num; e[++e_num]=(edge){v,u,head[v],0,0,-w}; head[v]=e_num; } bool spfa(int &c,int &f){ for(int i=0; i<=num; ++i) d[i]=INF,vis[i]=0; int hh,tt; d[s]=hh=tt=0; vis[s]=1; a[s]=INF; q[tt++]=s; while(hh!=tt){ int x=q[hh++]; hh%=maxd; vis[x]=0; for(int i=head[x]; i; i=e[i].next) if(e[i].cap>e[i].flow&&d[e[i].to]>d[x]+e[i].cost){ d[e[i].to]=d[x]+e[i].cost; fa[e[i].to]=i; a[e[i].to]=min(a[x],e[i].cap-e[i].flow); if(!vis[e[i].to]){ vis[e[i].to]=1; q[tt++]=e[i].to; tt%=maxd; } } } if(d[t]==INF) return 0; c+=d[t]*a[t]; f+=a[t]; int cur=t; while(cur!=s){ e[fa[cur]].flow+=a[t]; e[fa[cur]^1].flow-=a[t]; cur=e[fa[cur]].from; } return 1; } void get_cost(int &c,int &f){ c=f=0; while(spfa(c,f)); } int rr[10][2]; void work(){ e_num=1; memset(head,0,sizeof(head)); int cnt=0,n=read(),k=read(); s=n*2+1,t=num=s+1; int tt; tt=num=t+1; for(int i=1; i<=n; ++i){ int cur=read(); cnt+=cur; add_edge(i,t,cur,0); add_edge(s,i+n,cur,0); // if(i