codeforces 837 C

来源:互联网 发布:淘宝网团购 编辑:程序博客网 时间:2024/06/05 04:56
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 sizexi × 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 n,a and b (1 ≤ n, a, b ≤ 100).

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

Output

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

Examples
Input
2 2 21 22 1
Output
4
Input
4 10 92 31 15 109 11
Output
56
Input
3 10 106 67 720 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.

题意:

         给你一个a*b大小的一张纸,然后有n和个x*y大小的印章,纸张需要盖两个不同印章,求在不超出纸张大小的情况下盖在纸上的印章的最大面积

思路:

         用贪心的思路,求出每个印章的面积然后排序,从大到小取,枚举所取印章与其它印章的两两组合再判断是否能将两个印章都盖上,取最大值。

#include<iostream>#include<bits/stdc++.h>using namespace std;struct Node{    int x;    int y;    int ar;}node[110];int area[10010];bool cmp(Node x,Node y){    return x.ar>y.ar;}bool cmp1(int x,int y){    return x>y;}int main(){    int n,a,b;    while(scanf("%d%d%d",&n,&a,&b)!=EOF)    {        for(int i=0;i<n;i++){            scanf("%d%d",&node[i].x,&node[i].y);            node[i].ar=node[i].x*node[i].y;        }        sort(node,node+n,cmp);        int maxx=0;        for(int i=0;i<n;i++)        {            if(node[i].ar>a*b)                continue;            else if(max(node[i].x,node[i].y)>max(a,b)||min(node[i].x,node[i].y)>min(a,b))                continue;            int area=a*b;            area-=node[i].ar;            for(int j=i+1;j<n;j++)            {                if(node[j].ar>area)                    continue;                else if(max(node[j].x,node[j].y)>max(a,b)||min(node[j].x,node[j].y)>min(a,b))                    continue;                int d1=node[i].x+node[j].y;                int e1=max(node[i].y,node[j].x);                int d2=node[i].x+node[j].x;                int e2=max(node[i].y,node[j].y);                int d3=node[i].y+node[j].y;                int e3=max(node[j].x,node[i].x);                int d4=node[i].y+node[j].x;                int e4=max(node[i].x,node[j].y);               if((d1<=a&&e1<=b)||(d1<=b&&e1<=a)||(d2<=a&&e2<=b)||(d2<=b&&e2<=a)||(d3<=a&&e3<=b)||(d3<=b&&e3<=a)||(d4<=a&&e4<=b)||(d4<=b&&e4<=a))                    if(node[i].ar+node[j].ar>maxx)                        maxx=node[i].ar+node[j].ar;            }        }        printf("%d\n",maxx);    }    return 0;}