Pagini recente » Diferente pentru home intre reviziile 902 si 317 | Istoria paginii runda/pregatire-monthly8-ziua3/clasament | Cod sursa (job #2012181) | Cod sursa (job #2767968) | Cod sursa (job #2485220)
#include <fstream>
#include <iostream>
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()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
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;
updatel(l);
dr=t-1;
}
else
st=t+1;
}
cout<<mn<<"\n";
int cn=n;
while(cn and l>=0)
{
mat3[cn][1]=mat2[cn][l][1];
mat3[cn][2]=mat2[cn][l][2];
l-=mat3[cn][1];
cn--;
}
for(int i=1; i<=n; i++)
cout<<mat3[i][1]<<" "<<mat3[i][2]<<"\n";
return 0;
}