Pagini recente » Cod sursa (job #2601358) | Cod sursa (job #1788166) | Cod sursa (job #1758205) | Cod sursa (job #126726) | Cod sursa (job #2485206)
#include <bits/stdc++.h>
using namespace std;
int dp[105][105],mat[105][5],mat1[105][105][2],mat2[105][105][5],mat3[105][2];
int n,l,t,mn,st=1,dr=200,x;
void rreset()
{
for(int i=0; i<=n; i++)
for(int j=0; j<=l; j++)
dp[i][j]=-1;
dp[0][0]=0;
}
void update(int t)
{
for(int i=1; i<=n; i++)
for(int j=0; j<=l; j++)
for(x=0; x<=j; x++)
{
int lt2=(t-mat[i][1]*x)/mat[i][2];
if(dp[i][j]<dp[i-1][j-x]+lt2 and dp[i-1][j-x]>=0 and x*mat[i][1]<=t)
{
dp[i][j]=dp[i-1][j-x]+lt2;
mat1[i][j][1]=x;
mat1[i][j][2]=lt2;
}
}
}
void updatel(int l)
{
for(int i=1; i<=n; i++)
for(int j=0; j<=l; j++)
mat2[i][j][1]=mat1[i][j][1],mat2[i][j][2]=mat1[i][j][2];
}
int main()
{
ifstream cin("lapte.in");
ofstream cout("lapte.out");
cin>>n>>l;
for(int i=1; i<=n; i++)
cin>>mat[i][1]>>mat[i][2];
while(st<=dr)
{
t=(st+dr)/2;
rreset();
update(t);
if(dp[n][l]>=l)
{
mn=t;
dr=t-1;
updatel(l);
}
else
st=t+1;
}
cout<<mn<<"\n";
int cpn=n;
while(cpn and l>=0)
{
mat3[cpn][1]=mat2[cpn][l][1];
mat3[cpn][2]=mat2[cpn][l][2];
l-=mat3[cpn--][1];
}
for(int i=1; i<=n; i++)
cout<<mat3[i][1]<<" "<<mat3[i][2]<<"\n";
return 0;
}