Educational Round 26 C. Two Seals

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

One very important person has a piece of paper in the form of a rectangle a × b.

Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).

A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?

Input

The first line contains three integer numbers na and b (1 ≤ n, a, b ≤ 100).

Each of the next n lines contain two numbers xiyi (1 ≤ xi, yi ≤ 100).

 
Output

Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.

 
Examples
input
2 2 2
1 2
2 1
output
4
 
input
4 10 9
2 3
1 1
5 10
9 11
output
56
 
input
3 10 10
6 6
7 7
20 5
output
0
 
Note

In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.

In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.

 

给你几块印章,让你选出两块,使其盖在纸上时,在不超出纸张大小且必须与长宽平行的条件下,面积最大

In the third example there is no such pair of seals that they both can fit on a piece of paper

 

 1 #include <iostream>
 2 #include <stdio.h>
 3 using namespace std;
 4 int n, a, b;
 5 int x[120];
 6 int y[120];
 7 
 8 int main(){
 9     int ans=0;
10     cin>>n>>a>>b;
11     for(int i=0;i<n;i++)
12         cin>>x[i]>>y[i];
13     for(int i=0;i<n;i++){
14         for(int j=i+1;j<n;j++){
15             for(int it1=0;it1<2;it1++,swap(x[i],y[i])){
16                 for(int it2=0;it2<2;it2++,swap(x[j],y[j])){
17                     if(x[i]+x[j]<=a&&max(y[i],y[j])<=b)
18                         ans=max(x[i]*y[i]+x[j]*y[j],ans);
19                     if(x[i]+x[j]<=b&&max(y[i],y[j])<=a)
20                         ans=max(x[i]*y[i]+x[j]*y[j],ans);
21                 }
22             }
23         }
24     }
25     cout<<ans<<"\n";
26     return 0;
27 }

 

posted @ 2017-08-06 18:45  浅忆~  阅读(169)  评论(0编辑  收藏  举报