Pagini recente » Cod sursa (job #2468025) | Cod sursa (job #3121313) | Cod sursa (job #3203762) | Cod sursa (job #3283596) | Cod sursa (job #480196)
Cod sursa(job #480196)
#include <fstream>
using namespace std;
ifstream cin("lapte.in");
ofstream cout("lapte.out");
int n, l, i, j, k;
int a[101], b[101];
int d[101][101], last[101][101];
bool sol(int t)
{
memset(d, -1, sizeof(d));
int A = 0, B = 0;
int i, j, k, val;
d[0][0] = 0;
for(i=1;i<=n;++i)
for(j=0;j<=l;++j)
if(d[i-1][j] != -1)
for(k=min(l-j, t / a[i]);k>=0;--k)
{
val = (t - k * a[i]) / b[i] + d[i-1][j];
if (val > d[i][j+k])
d[i][j+k] = val,
last[i][j+k] = j;
}
return d[n][l] >= l;
}
void print(int i, int j)
{
if(i==0)
return;
int val = d[i][j] - d[i-1][last[i][j]];
print(i - 1, last[i][j]);
cout << j - last[i][j] << " " << val << "\n";
}
int main()
{
cin >> n >> l;
for(int i=1;i<=n;++i)
cin >> a[i] >> b[i];
int st = 0, dr = 0x3fffffff, mij;
while(st < dr)
{
mij = (st + dr) >> 1;
if(sol(mij))
dr = mij;
else
st = mij + 1;
}
cout << st << endl;
print(n, l);
return 0;
}