analysis
ans1=max (l0 / r1,l0 * l1 / r2)
ans2=max (l0 / r2,l0 * l2 / r1)
can be compared to get
l0 / r1 <l0 * l2 / r1
l0 / r2 <l0 * l1 / r2
Assuming ans1<ans2,
then l0 * l1 / r2 <l0 * l2 / r1
use the eighth grade fractional equation solution method to get
l1 * r1 <l2 * r2
and find the answer after fast sorting
Remember to increase precision
Upload code
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,c,t,l;
int sum[10001],d[10001],ans[10001];
struct node
{
int l,r;
}a[2001];
int cmp(node l,node y)
{
return l.l*l.r<y.l*y.r;
}
void jq(int x)
{
int w=0;
for(int i=1;i<=l;i++)
{
sum[i]=sum[i]*x+w;
w=sum[i]/10;
sum[i]=sum[i]%10;
}
while(w)
{
sum[++l]=w%10;
w=w/10;
}
}
void div(int x)
{
int w=0;
c=1;
memset(d,0,sizeof(d));
for(int i=l;i>0;i--)
{
w=w*10+sum[i];
d[i]=w/x;
if(d[i]!=0&&c==1) c=i;
w=w%x;
}
}
int pd()
{
if(t>c) return 0;
if(c>t)
{
t=c;
return 1;
}
for(int i=1;i<=t;i++)
{
if(ans[i]<d[i]) return 1;
}
return 0;
}
int main()
{
cin>>n;
l=1;
sum[1]=1;
for(int i=0;i<=n;i++)
{
cin>>a[i].l>>a[i].r;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++)
{
jq(a[i-1].l);
div(a[i].r);
if(pd())
{
for(int i=1;i<=t;i++)
{
ans[i]=d[i];
}
}
}
for(int i=t;i>=1;i--)
{
cout<<ans[i];
}
return 0;
}