Description
Dasha decided to bake a big and tasty layer cake. In order to do that she went shopping and bought n rectangular cake layers. The length and the width of the i-th cake layer were ai and bi respectively, while the height of each cake layer was equal to one.
From a cooking book Dasha learned that a cake must have a form of a rectangular parallelepiped constructed from cake layers of the same sizes.
Dasha decided to bake the biggest possible cake from the bought cake layers (possibly, using only some of them). It means that she wants the volume of the cake to be as big as possible. To reach this goal, Dasha can cut rectangular pieces out of the bought cake layers. She always cuts cake layers in such a way that cutting lines are parallel to the edges of that cake layer. Dasha isn't very good at geometry, so after cutting out a piece from the original cake layer, she throws away the remaining part of it. Also she can rotate a cake layer in the horizontal plane (swap its width and length).
Dasha wants her cake to be constructed as a stack of cake layers of the same sizes. Each layer of the resulting cake should be made out of only one cake layer (the original one or cut out from the original cake layer).
Help Dasha to calculate the maximum possible volume of the cake she can bake using given cake layers.
Input
The first line contains an integer n(1 ≤ n ≤ 4000) — the number of cake layers that Dasha can use.
Each of the following n lines contains two integer numbers ai and bi(1 ≤ ai, bi ≤ 106) — the length and the width of i-th cake layer respectively.
Output
The first line of the output should contain the maximum volume of cake that can be baked using given layers.
The second line of the output should contain the length and the width of the resulting cake. If there are many solutions with maximum possible volume, print any of them.
Sample Input
5
5 12
1 1
4 6
6 4
4 6
96
6 4
2
100001 900000
900001 100000
180000000000
900000 100000
Hint
In the first example Dasha doesn't use the second cake layer. She cuts 4 × 6 rectangle from the first cake layer and she uses other cake layers as is.
In the second example Dasha cuts off slightly from the both cake layers.
巧妙得利用了set....
注意因为可能有重复元素。。。所以要用multiset...
然后有点喜欢上用pair了hhh
队友是二维bit+熔池过掉的。。。。
1 /************************************************************************* 2 > File Name: code/hust/20151025/BB.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年10月27日 星期二 14时34分16秒 6 ************************************************************************/ 7 8 #include<iostream> 9 #include<iomanip> 10 #include<cstdio> 11 #include<algorithm> 12 #include<cmath> 13 #include<cstring> 14 #include<string> 15 #include<map> 16 #include<set> 17 #include<queue> 18 #include<vector> 19 #include<stack> 20 #include<cctype> 21 22 #define yn hez111qqz 23 #define j1 cute111qqz 24 #define ms(a,x) memset(a,x,sizeof(a)) 25 #define sec second 26 #define fir first 27 using namespace std; 28 const int dx4[4]={1,0,0,-1}; 29 const int dy4[4]={0,-1,1,0}; 30 typedef long long LL; 31 typedef double DB; 32 const int inf = 0x3f3f3f3f; 33 34 const int N=4E3+7; 35 int n; 36 LL mx,cura,curb; 37 pair<LL,LL> a[N]; 38 multiset<LL> se; 39 multiset<LL> ::iterator it; 40 int main() 41 { 42 #ifndef ONLINE_JUDGE 43 freopen("in.txt","r",stdin); 44 #endif 45 46 scanf("%d",&n); 47 for ( int i = 0 ; i < n ; i++) 48 { 49 scanf("%lld %lld",&a[i].fir,&a[i].sec); 50 if (a[i].fir>a[i].sec) swap(a[i].fir,a[i].sec); 51 } 52 sort(a,a+n); 53 mx = -1; 54 for ( int i = n -1 ; i >= 0 ; i--) 55 { 56 se.insert(a[i].sec); 57 it =se.begin(); 58 for ( int j = i ; j < n ; j++) 59 { 60 LL tmp =a[i].fir*(*it)*(n-j); 61 if (tmp>mx) 62 { 63 mx = tmp; 64 cura = a[i].fir; 65 curb = *it; 66 } 67 it++; 68 } 69 } 70 printf("%lld %lld %lld ",mx,curb,cura); 71 72 73 #ifndef ONLINE_JUDGE 74 fclose(stdin); 75 #endif 76 return 0; 77 }