http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2401
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=1010;
struct node
{
int x,y;
}mem[N];
bool cmp(node a,node b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
bool cmp1(node a,node b)
{
if(a.y==b.y)
return a.x<b.x;
return a.y<b.y;
}
int main()
{
//freopen("data.txt","r",stdin);
int T;
int L,W,Point;
cin>>T;
while(T--)
{
cin>>L>>W;
mem[0].x=0;mem[0].y=0;
mem[1].x=0;mem[1].y=W;
mem[2].x=L;mem[2].y=0;
mem[3].x=L;mem[3].y=W;
cin>>Point;
for(int i=4;i<4+Point;++i)
{
cin>>mem[i].x>>mem[i].y;
}
sort(mem,mem+Point+4,cmp);
int ans=0;
for(int i=0;i<Point+4;++i)
{
for(int j=i+1,low=0,high=W,Maxl=L-mem[i].x;j<Point+4;++j)
{
if(mem[j].y<=high&&mem[j].y>=low)
{
ans=max(ans,(high-low)*(mem[j].x-mem[i].x));
if(mem[j].y==mem[i].y)
break;
if(mem[j].y<mem[i].y)
low=mem[j].y;
else
high=mem[j].y;
if((high-low)*Maxl<=ans)
break;
}
}
}
sort(mem,mem+Point+4,cmp1);
for(int i=0;i<Point+4;++i)
{
for(int j=i+1,low=0,high=L,Maxl=W-mem[i].y;j<Point+4;++j)
{
if(mem[j].x<=high&&mem[j].x>=low)
{
ans=max(ans,(high-low)*(mem[j].y-mem[i].y));
if(mem[j].x==mem[i].x)
break;
if(mem[j].x<mem[i].x)
low=mem[j].x;
else
high=mem[j].x;
if((high-low)*Maxl<=ans)
break;
}
}
}
cout<<ans<<endl;
}
return 0;
}