二分答案
#include<stdio.h> int main() { long long int m,n,r,a,b,c,x,y,z,k,i,left,right,mid,h,f,e,p,s,g; while(scanf("%lld %lld %lld",&a,&b,&c)!=EOF) { scanf("%lld %lld %lld",&m,&n,&r); scanf("%lld %lld %lld %lld",&k,&x,&y,&z); s=(m/a<n/b)?m/a:n/b; left=(s<r/c)?s:r/c; right=(m*x+n*y+r*z+k)/(a*x+b*y+c*z); while(left<=right) { h=0;f=0;e=0,g=0; mid=(left+right)/2; if(mid*a>m) { h=mid*a-m; } if(mid*b>n) { f=mid*b-n; } if(mid*c>r) { e=mid*c-r; } if(k>(h*x+f*y+e*z)) left=mid+1; else if(k<(h*x+f*y+e*z)) right=mid-1; else { printf("%lld\n",mid); g=1; break; } } if(g==0) printf("%lld\n",left-1); } }