Educational Codeforces Round 26 C. Two Seals

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.


输入n  a  b 代表你现在有n张海报 然后你还有一张矩形的纸 长和宽分别为a 和b(a和b不一定谁大谁小)

问 你现在要把两张海报贴到这张a*b的纸上面 海报必须在纸内不能露出纸外 且两张海报不能重叠 问你这两张海报面积之和的最大值

思路:先放其中一张 分为横着放和竖着放(放第一张海报的时候要紧挨着纸边放)  放好第一张以后会空出两部分区域 再看第二张能否放在这两部分区域的其中一部分区域中 如果能的话更新最大值就好了

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<stack>
#include<queue>
#include<cmath>
#include<stack>
#include<list>
#include<set>
typedef long long ll;
using namespace std;
int a,b;
int n;
struct node
{
    int x, y;
}code[210]; //名字起的有点随意 请谅解
int mianji(int s,int t)
{
    return s*t;
}
int cal()
{
    int i,j;
    int x1,y1;
    int x2,y2;
    int x3,y3;
    int x4,y4;
    int maxn=0;//初始化为0
    for(i=1;i<=n;i++)
    {
        x1=code[i].x; //x1和y1记录第一张海报的长和宽
        y1=code[i].y;
        for(j=i+1;j<=n;++j)
        {
            int flag=1; //==1代表还没有放进去
            x2=code[j].x; //x2和y2记录第二张海报的长和宽
            y2=code[j].y;
            if(x1<=a&&y1<=b)//第一张横着放 而且放得进去
            {
                x3=a-x1; //x3 y3 x4 y4分别记录放完第一张海报后剩余的两部分
                y3=b;
                x4=b-y1;
                y4=a;
                
                if(x2<=x3&&y2<=y3||x2<=x4&&y2<=y4||x2<=y3&&y2<=x3||x2<=y4&&y2<=x4)
                {
                    maxn=max(maxn,mianji(x1,y1)+mianji(x2,y2));
                    flag=0;
                }
            }
            if(flag)//如果第一张横着放的情况下 第二张放不进去 说明没能满足条件 尝试第二种情况
            {
                if(x1<=b&&y1<=a)//第一张竖着放 而且放得进去
                {
                    x3=a-y1;
                    y3=b;
                    x4=b-x1;
                    y4=a;
                    if(x2<=x3&&y2<=y3 || x2<=x4&&y2<=y4 || x2<=y3&&y2<=x3 || x2<=y4&&y2<=x4)
                    {
                        maxn=max(maxn,mianji(x1,y1)+mianji(x2,y2));
                        flag=0;
                    }
                }
                
            }
        }
    }
    return maxn;
    
}
int main()
{
    
    int i,j,k;
  
    while(scanf("%d",&n)==1)
    {
        scanf("%d%d",&a,&b);
        if(a>b)
        {
            int temp=a;
            a=b;b=temp;
        }
        int x,y;
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&x,&y);
            if(x>y)
            {
                int temp=x;
                x=y;
                y=temp;
            }
            code[i].x=x;
            code[i].y=y;
        }
        printf("%d\n",cal());
        
    }
    return 0;
    
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值