http://codeforces.com/problemset/problem/837/C
给定n,a,b,有n张海报,一张a*b的矩形纸张。
现要把2张海报贴到这张a*b的纸上面,海报必须在纸内不能露出纸外 且两张海报不能重叠 问你这两张海报面积之和的最大值
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
struct P{
int l;
int w;
int s;
}p[105];
int n,L,W;
int sum;
int ans=0;
bool ok(int x1,int y1,int x2,int y2){
if ((x1<=x2&&y1<=y2)||(x1<=y2&&y1<=x2)){
return true;
}
else{
return false;
}
}
bool cmp(struct P a,struct P b){
return a.s>b.s;
}
int main(){
cin >> n >> L >> W;
if (L<W){
swap(L,W);
}
for (int i=0;i<n;i++){
cin >> p[i].l >> p[i].w;
if (p[i].l<p[i].w){
swap(p[i].l,p[i].w);
}
p[i].s=p[i].l*p[i].w;
}
sort(p,p+n,cmp);
for (int i=0;i<n-1;i++){
if (!ok(p[i].l,p[i].w,L,W)){
continue;
}
sum=p[i].s;
int tL;
int tW;
if (p[i].l<=W){
tL=L-p[i].w;
tW=W-p[i].l;
for (int j=i+1;j<n;j++){
if (ok(p[j].l,p[j].w,tL,W)||ok(p[j].l,p[j].w,L,tW)){
ans=max(ans,sum+p[j].s);
}
}
}
tL=L-p[i].l;
tW=W-p[i].w;
for (int j=i+1;j<n;j++){
if (ok(p[j].l,p[j].w,tL,W)||ok(p[j].l,p[j].w,L,tW)){
ans=max(ans,sum+p[j].s);
}
}
}
cout << ans << endl;
}