Cod sursa(job #766518)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("lapte.in");
ofstream out("lapte.out");
const int N=105;
int n,l;
struct point
{
int a,b;
};
point x[N];
bool cmp(point x, point y)
{
return (double)(x.b-x.a)/(x.a*x.b)> (double)(y.b-y.a)/(y.a*y.b);
}
bool ok(int t)
{
int la=0,lb=0,k;
k=1;
while(la<l)
{
la+=t/x[k].a;
k++;
}
lb+=((la-l)*x[k-1].a)/x[k-1].b;
while(k<=n)
{
lb+=t/x[k].b;
k++;
}
if(lb>=l)
return true;
return false;
}
int bs()
{
int i,pas=1<<16;
for(i=1;pas;pas>>=1)
{
if(i+pas<=N && !ok(i+pas))
i+=pas;
}
return i+1;
}
int main()
{
int i;
in>>n>>l;
for(i=1;i<=n;i++)
in>>x[i].a>>x[i].b;
sort(&x[1],&x[n+1],cmp);
out<<bs()<<"\n";
return 0;
}