题目
分析
代码
1 #include<iostream>
2 #include<cstdio>
3 using namespace std;
4 int a[1001],b[1001];
5 int f[1001][1001];
6 int n,m;
7 bool check(int mid)
8 {
9 for (int i=0;i<=n;i++)
10 for (int j=0;j<=m;j++)
11 f[i][j]=-1e9;
12 f[0][0]=0;
13 for (int i=1;i<=n;i++)
14 for (int j=0;j<=m;j++)
15 for (int k=0;k<=j;k++)
16 {
17 if(mid-k*a[i]<0) break;
18 f[i][j]=max(f[i][j],f[i-1][j-k]+(int)((mid-k*a[i])/b[i]));
19 }
20
21 if (f[n][m]>=m) return true;
22 else return false;
23 }
24 int main ()
25 {
26 freopen("company.in","r",stdin);
27 freopen("company.out","w",stdout);
28 cin>>n>>m;
29 for (int i=1,x,y;i<=n;i++)
30 cin>>a[i]>>b[i];
31 int l=1,r=10000,mid;
32 while (l<=r)
33 {
34 mid=l+r>>1;
35 if (check(mid)) r=mid-1;
36 else l=mid+1;
37 }
38 cout<<l;
39 }