#include #include #include #include using namespace std; struct px { int a,b; } node; vector a,b; bool cmp(const struct px &x,const struct px &y) { return x.a=b[i].a) { ansn++; mn+=b[i].a; } } if(a.size()>0&&a[0].a<=m) { node=a[0]; mm+=node.a; for(int i=0; i0&&a[0].a<=m-mn) { node=a[0]; mn+=node.a; for(int i=0; i=0; --idb,--bx,++ans); if(idb<0) { if(ans>ansn) printf("Case %d: %d %d\n",cas,ans,mm); else if(ansmm?mm:mn); } else { int i,j; for(i=1,j=0; i=a[i].a+mm) { mm+=a[i].a; i++; ans++; idb--; } else break; } else { if(m>=b[j].a+mm) { mm+=b[j].a; ans++; j++; } else break; } } for(;j<=idb;++j) { if(m>=b[j].a+mm) { mm+=b[j].a; ans++; j++; } else break; } if(ans>ansn) printf("Case %d: %d %d\n",cas,ans,mm); else if(ansmm?mm:mn); } } return 0; }