#include<bits/stdc++.h>
using namespace std;
struct m{
int a,b,ab;
}ms[1001];
int cmp2(int a[],int b[]){
if (a[0] > b[0]) return 1;
if(a[0] < b[0]) return 0;
for (int i = a[0];i >= 1;i--){
if (a[i] > b[i]) return 1;
if (a[i] < b[i]) return 0;
}
return 0;
}
bool cmp(m m1,m m2){
return m1.ab < m2.ab;
}
void divi(int a[],int b,int c[]){
int y = 0;
for (int i = a[0];i >= 1;i--){
int temp = y*10+a[i];
c[i] = temp/b;
y = temp%b;
}
int len = a[0];
while(c[len] == 0 && len > 1) len--;
c[0] = len;
}
void multi(int a[],int b){
int b1[5],lenb = 0;
while(b){
lenb++;
b1[lenb] = b%10;
b /= 10;
}
int temp[4001] = {},len = a[0] + lenb,x=0;
for (int i = 1;i <= lenb;i++){
for (int j = 1;j <= a[0];j++){
temp[i+j-1] += b1[i]*a[j]+x;
x = temp[i+j-1]/10;
temp[i+j-1] %= 10;
}
if (x){
temp[i+a[0]] = x;
x = 0;
}
}
while(temp[len] == 0 && len > 1) len--;
temp[0] = len;
memcpy(a,temp,sizeof(temp));
}
void calc(int n){
int s[4001] = {1,1};
int ans[4001] = {};
int maxgn[4001]={};
multi(s,ms[0].a);
for (int i = 1;i <= n;i++){
divi(s,ms[n].b,ans); //计算第i个人拿到的金币
if(cmp2(ans,maxgn)) memcpy(maxgn,ans,sizeof(ans));
multi(s,ms[i].a);
}
//printf("%d",s[0]);
//for (int i = s[0];i > 0;i--) printf("%d",s[i]);
for (int i = ans[0];i > 0;i--) printf("%d",maxgn[i]);
}
int main(){
int n;
cin>>n;
scanf("%d%d",&(ms[0].a),&(ms[0].b));
for (int i = 1;i <= n;i++){
scanf("%d%d",&(ms[i].a),&(ms[i].b));
ms[i].ab = ms[i].a * ms[i].b;
}
sort(ms+1,ms+n+1,cmp);
calc(n);
return 0;
}
高手求调,WA 2,怎么改都不对