Pagini recente » Cod sursa (job #2632237) | Cod sursa (job #2451134) | Cod sursa (job #1633644) | Cod sursa (job #2458132) | Cod sursa (job #1252066)
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int n,l,a[105],b[105];
int d[105][105];
int x[105][105];
struct lapte
{
int a,b;
};
vector<lapte>v;
void ok(int t)
{
int i,j,k;
memset(d,0,sizeof(d));
for(i=1;i<=l;++i)
d[0][i]=-1000000000;
for(i=1;i<=n;++i)
for(j=0;j<=l;++j)
{
x[i][j]=0;
d[i][j]=d[i-1][j]+t/b[i];
for(k=0;k<=t/a[i] && k<=j;++k)
{
if (d[i][j]<d[i-1][j-k]+(t-k*a[i])/b[i])
{
d[i][j]=d[i-1][j-k]+(t-k*a[i])/b[i];
x[i][j]=k;
}
}
}
}
int bs(int st,int dr)
{
int nr,med;
nr=dr;
while(st<=dr)
{
med=st+(dr-st)/2;
ok(med);
if (d[n][l]>=l)
{
nr=med;
dr=med-1;
}
else
st=med+1;
}
return nr;
}
int main()
{
freopen("lapte.in","r",stdin);
freopen("lapte.out","w",stdout);
int i;
scanf("%d%d",&n,&l);
for(i=1;i<=n;++i)
scanf("%d%d",&a[i],&b[i]);
int nr = bs(1,l*(a[1]+b[1]));
ok(nr);
printf("%d\n",nr);
int m=0;
lapte aux;
for(i=n;i>=1;--i)
{
aux.a=x[i][l];
aux.b=(nr-aux.a*a[i])/b[i];
v.push_back(aux);
l=l-x[i][l];
++m;
}
for(i=m-1;i>=0;--i)
printf("%d %d\n",v[i].a,v[i].b);
return 0;
}