#include <bits/stdc++.h> using namespace std; const int base=400; int f[205][25][805]; int p[205],d[205]; int main() { int n,m,T=1; while(scanf("%d%d",&n,&m)!=EOF) { if(n==0&&m==0) break; for(int i=1;i<=n;i++) scanf("%d%d",&p[i],&d[i]); memset(f,-0x3f,sizeof f); f[0][0][base]=0; for(int i=1;i<=n;i++) { for(int j=0;j<=m;j++) { for(int k=0;k<=800;k++) { int x=d[i]-p[i]; //不选 f[i][j][k]=max(f[i][j][k],f[i-1][j][k]); //选 if(k-x<0||k-x>800) continue; if(j) f[i][j][k]=max(f[i][j][k],f[i-1][j-1][k-x]+p[i]+d[i]); } } } int v=0; while(f[n][m][base+v]<0&&f[n][m][base-v]<0) v++;//找v if(f[n][m][base-v]>f[n][m][base+v]) v=base-v;//选择最佳方案。 else v=base+v; int i=n,j=m,k=v,cnt=0,ans[205],ansd=0,ansp=0; while(j) { if(f[i][j][k]==f[i-1][j][k])//说明这个地方可以不选. { i--; } else { ansd+=d[i]; ansp+=p[i]; k-=d[i]-p[i]; ans[cnt++]=i; i--; j--; } } printf("Jury #%d\n",T++); printf("Best jury has value %d for prosecution and value %d for defence:\n",ansp,ansd); for(int i=cnt-1;i>=0;i--) { printf(" %d",ans[i]); } printf("\n\n"); } return 0; }