codeforces 837 C

解决在一纸张上放置两个不同印章的问题,使印章总面积最大化且不超出纸张范围。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 n, a and b (1 ≤ n, a, b ≤ 100).

Each of the next n lines contain two numbers xi, 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, 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.

题意:

         给你一个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;
}


### Codeforces Problem 1332C Explanation The provided references pertain specifically to problem 742B on Codeforces rather than problem 1332C. For an accurate understanding and solution approach for problem 1332C, it's essential to refer directly to its description and constraints. However, based on general knowledge regarding competitive programming problems found on platforms like Codeforces: Problem 1332C typically involves algorithmic challenges that require efficient data structures or algorithms such as dynamic programming, graph theory, greedy algorithms, etc., depending upon the specific nature of the task described within this particular question[^6]. To provide a detailed explanation or demonstration concerning **Codeforces problem 1332C**, one would need direct access to the exact statement associated with this challenge since different tasks demand tailored strategies addressing their unique requirements. For obtaining precise details about problem 1332C including any sample inputs/outputs along with explanations or solutions, visiting the official Codeforces website and navigating to contest number 1332 followed by examining section C is recommended. ```python # Example pseudo-code structure often seen in solving competitive coding questions. def solve_problem_1332C(input_data): # Placeholder function body; actual logic depends heavily on the specifics of problem 1332C. processed_result = process_input(input_data) final_answer = compute_solution(processed_result) return final_answer input_example = "Example Input" print(solve_problem_1332C(input_example)) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值