题目描述
恰逢 H国国庆,国王邀请n 位大臣来玩一个有奖游戏。首先,他让每个大臣在左、右手上面分别写下一个整数,国王自己也在左、右手上各写一个整数。然后,让这 n 位大臣排成一排,国王站在队伍的最前面。排好队后,所有的大臣都会获得国王奖赏的若干金币,每位大臣获得的金币数分别是:排在该大臣前面的所有人的左手上的数的乘积除以他自己右手上的数,然后向下取整得到的结果。
国王不希望某一个大臣获得特别多的奖赏,所以他想请你帮他重新安排一下队伍的顺序,使得获得奖赏最多的大臣,所获奖赏尽可能的少。注意,国王的位置始终在队伍的最前面。

==输入格式==
第一行包含一个整数n,表示大臣的人数。
第二行包含两个整数 a和 b,之间用一个空格隔开,分别表示国王左手和右手上的整数。
接下来 n行,每行包含两个整数a 和 b,之间用一个空格隔开,分别表示每个大臣左手和右手上的整数。
==输出格式==
一个整数,表示重新排列后的队伍中获奖赏最多的大臣所获得的金币数。
输入输出样例
输入
3
1 1
2 3
7 4
4 6
输出
2

考虑相邻的两个 a( l1 , r1 ),b ( l2 , r2 ),假设之前的代价值为 x ,
a 在前时 ,代价 = x l1 / r2;
b 在前时 ,代价 = x
l2 / r1;
所以按( l(a) / r(b) )排序即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <bits/stdc++.h>
using namespace std;
#define sf(n) scanf("%d",&n)
#define fi(i,s,t) for(int i=s;i<t;i++)
const int MAX=1000+10;
struct BigInt{
const static int mod =10000;
const static int DLEN=4;
int a[36000],len,flag;//正负
BigInt(){
memset(a,0,sizeof(a));
len=1;
flag =1;
}
BigInt(int v){
memset(a,0,sizeof(a));
if(v<0) flag=-1;
else flag =1;
len=0;
do{
a[len++]=v%mod;
v/=mod;
}while(v);
}
BigInt(const char s[]){
memset(a,0,sizeof(a));
int inc=0;
if(s[0]=='-')flag= -1,inc=1;
else flag=1;
int L=strlen(s+inc);
len =L/DLEN;
if(L%DLEN) len++;
int index=0;
for(int i=L-1+inc;i>=inc;i-=DLEN){
int t=0;
int k=i-DLEN +1;
if(k<inc) k=inc;
for(int j=k;j<=i;j++)
t=t*10 + s[j] -'0';
a[index++] =t;
}
}
bool operator >(const BigInt &b)const{
int ln;
if(len > b.len || (flag ==1 && b.flag==-1)) return true;
else if(len==b.len){
ln = len-1;
while(a[ln]==b.a[ln]&&ln>=0)ln--;
if(ln>=0&&a[ln]>b.a[ln])
return true;
else
return false;
}
else return false;
}
BigInt operator -(const BigInt &b)const{
if(flag!=b.flag){//减负数转加法
BigInt c=*this,d=b;
if(c.flag==1&&d.flag==-1){
d.flag=1;
return c+d;
} else if(c.flag==-1&&d.flag==1){
c.flag=1;
BigInt e= c+d;
e.flag=-1;
return e;
}
}
int i,j,big;
bool flag;
BigInt t1,t2;
if(*this>b){
t1=*this;
t2=b;
flag=0;
}else {
t1=b;
t2=*this;
flag=1;
}
big=t1.len;
for(i=0;i<big;i++){
if(t1.a[i]<t2.a[i]){
j=i+1;
while(t1.a[j]==0) j++;
t1.a[j--]--;
while(j>i)
t1.a[j--]+=mod-1;
t1.a[i]+=mod-t2.a[i];
}else t1.a[i]-=t2.a[i];
}
t1.len=big;
while(t1.a[t1.len-1]==0&&t1.len>1){
t1.len--;
big--;
}
if(flag) t1.a[big-1]=0-t1.a[big-1];
return t1;
}
BigInt operator +(const BigInt &b)const{
if(flag!=b.flag){//加负数转减法
BigInt tmp=b,tmp1=*this;
if(tmp1>tmp) {
tmp.flag=1;
return tmp1-tmp;
}
else{
tmp1.flag=1;
return tmp-tmp1;
}
}
BigInt res;
res.len=max(len,b.len);
for(int i=0;i<=res.len;i++)
res.a[i]=0;
for(int i=0;i<res.len;i++){
res.a[i]+=((i<len)?a[i]:0)+((i<b.len)?b.a[i]:0);
res.a[i+1]+=res.a[i]/mod;
res.a[i]%=mod;
}
if(res.a[res.len]>0) res.len++;
return res;
}
BigInt operator /(const int &b) const{ //大数除整数
BigInt res;
int i,down=0,ins=0,tmp=b;
if(b<0)tmp=-b;
for(i=len-1;i>=0;i--){
res.a[i]=(a[i]+down*mod)/tmp;
down =a[i]+down * mod - res.a[i]*tmp;
}
res.len=len;
res.flag = flag * (b<0?-1:1);
while(res.a[res.len-1]==0&&res.len>1)res.len--;
return res;
}
BigInt operator *(const BigInt &b) const{
BigInt res;
for(int i=0;i<len;i++){
int up=0;
for(int j=0;j<b.len;j++){
int temp =a[i] * b.a[j] + res.a[i+j] +up;
res.a[i+j] =temp % mod;
up=temp/mod;
}
if(up)
res.a[i+b.len] =up;
}
res.len =len + b.len;
while(res.a[res.len -1] == 0 && res.len >1) res.len--;
res.flag = flag * b.flag;
return res;
}
void output(){
if(flag==-1) printf("-");
printf("%d",a[len-1]);
for(int i=len-2;i>=0;i--)
printf("%04d",a[i]);
printf("\n");
}
};
int n,a,b;
BigInt sum,ans;
pair<int,int>p[MAX];
int cmp(pair<int,int> x,pair<int,int> y){
return x.first *1.0 /y.second < y.first *1.0 /x.second ;
}
int main(){
freopen("in","r",stdin);
sf(n);
sf(a);sf(b);
fi(i,0,n){
sf(p[i].first);sf(p[i].second);
}
sort(p,p+n,cmp);
sum = BigInt(a);ans =BigInt(0);
fi(i,0,n){
if(sum/p[i].second > ans) ans =sum/p[i].second ;
sum =sum * BigInt(p[i].first);
}
ans.output();
return 0;
}