#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=2010;
int n,m,a[MAXN],b[MAXN],c[MAXN],d[MAXN],ans=1e9;
void dfs(int x,int y,int maxx,int maxy){
if(ans<=maxx+maxy)return;
if(y>m)x++,y=1;
if(x==n&&y==m){//cout<<x<<" "<<y<<" "<<maxx<<" "<<maxy<<endl;
ans=min(ans,maxy+maxx);
return;
}
int nmaxx=c[y]-a[x]+1,nmaxy=d[y]-b[x]+1;
if(maxx>nmaxx||maxy>nmaxy)dfs(x,y+1,maxx,maxy);
else {
dfs(x,y+1,maxx,nmaxy);
dfs(x,y+1,nmaxx,maxy);
}
}
signed main(){
//freopen("light.in","r",stdin);
//freopen("light.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
for(int i=1;i<=m;i++)cin>>c[i]>>d[i];
dfs(1,1,0,0);
cout<<ans;
return 0;
}/*
7 3
0 8
3 8
2 7
0 10
5 5
7 0
3 5
6 6
3 11
11 5
*/
luoyangshu
1492218
资料、奖项与版本
个人介绍
文章
共 1 篇- 题解