1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| #include <iostream> #include <stdio.h> #include <algorithm> #include <string> #include <cstring> #include <math.h> #include <map> #include <queue> using namespace std; typedef long long ll; const int inf = 0x3f3f3f3f; const double eps = 1e-8; #define pi acos(-1.0) int n,s; const int maxn = 105; int x[maxn],y[maxn],s1[maxn],s2[maxn],p1[maxn],p2[maxn]; int f[8000005]; int S[2],P[2]; int cal(int num, int data, int need) { S[0] = s1[num]; S[1] = s2[num]; P[0] = p1[num]; P[1] = p2[num]; int v = need + s2[num]; for(int i = 1; i <= v; ++i) f[i] = inf; f[0] = 0; for(int i = 0; i < 2; ++i) { for(int j = S[i] ; j <= v; ++j) { f[j] = min(f[j], f[j - S[i]] + P[i]); } } int ret = inf; for(int i = need ; i <= v ; ++i) ret = min(ret, f[i]); return ret; }
bool judge(int data) { int sum = 0; for(int i = 1; i <= n; ++i) { if(data * x[i] - y[i] <= 0) continue; sum += cal(i, data, data * x[i] - y[i]); if(sum > s) return 1; } return 0; }
int a[100005]; int main() { while(scanf("%d %d",&n,&s) != EOF) { if(n == 0 && s == 0)break; int Min = inf; for(int i = 1; i <= n; ++i) { scanf("%d %d %d %d %d %d",&x[i],&y[i],&s1[i],&p1[i],&s2[i],&p2[i]); if((s1[i] * 1.0)/ p1[i] > (s2[i] * 1.0)/ p2[i]) { int k = ((y[i] + (s * 1.0)/ p1[i] * s1[i]) * 1.0) / x[i] +5; if(k < Min) Min = k; } else{ int k = ((y[i] + (s * 1.0)/ p2[i] * s2[i]) *1.0) / x[i] +5; if(k < Min) Min = k; } } int l = 0, r = Min; int mid ; while(l <= r) { mid = (l + r) >> 1; if(judge(mid)) r = mid - 1; else l = mid + 1; } printf("%d\n",r); } }
|