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; }
|