C - Two Seals
CodeForces - 837C
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.
Example
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.
题意:有一个矩形区域,你有很多小矩形,选两个小矩形放到大矩形区域中,小矩形不重叠,怎样选择使覆盖面积最大,求最大面积
解法:四种放法,两个都正放,两个都竖放,一正一竖
代码:
#include<iostream>
#include<stdio.h>
using namespace std;
int x[100],y[100];
int main()
{
int n,a,b,i,ans=0;
cin>>n>>a>>b;
for(i=0;i<n;i++)
cin>>x[i]>>y[i];
int xx,yy;
for(int j=0;j<i;j++){
for(int k=j+1;k<i;k++){
xx=x[j]+x[k];
yy=max(y[j],y[k]);
if(min(xx,yy)<=min(a,b)&&max(xx,yy)<=max(a,b)){
ans=max(ans,x[j]*y[j]+x[k]*y[k]);
continue;
}
xx=x[j]+y[k];
yy=max(y[j],x[k]);
if(min(xx,yy)<=min(a,b)&&max(xx,yy)<=max(a,b)){
ans=max(ans,x[j]*y[j]+x[k]*y[k]);
continue;
}
xx=y[j]+x[k];
yy=max(x[j],y[k]);
if(min(xx,yy)<=min(a,b)&&max(xx,yy)<=max(a,b)){
ans=max(ans,x[j]*y[j]+x[k]*y[k]);
continue;
}
xx=y[j]+y[k];
yy=max(x[j],x[k]);
if(min(xx,yy)<=min(a,b)&&max(xx,yy)<=max(a,b))
ans=max(ans,x[j]*y[j]+x[k]*y[k]);
}
}
printf("%d\n",ans);
return 0;
}