#include using namespace std; template class Cumulative2D{ //2次元 まだ洗練されてない. private: T op(T a,T b){return a+b;} //基本足し算なので固定. T inv(T a){return -a;} //ない場合はスルー->rangeans使用不可. T e(){return 0;} int h,w; bool okB = false; vector> A; vector> B[4]; public: void make(vector> &a,bool ope = true){ //ope=累積opをとる. A = a; h = A.size(),w = A.at(0).size(); if(!ope) return; for(int i=0; i f){ //Aに対して上下左右から累積fをとりBとする. //0左上,1右上,2左下,3右下. okB = true; for(auto &b : B) b = A; for(int i=0; i=0; k--) B[1][i][k] = f(B[1][i][k],B[1][i][k+1]); for(int i=1; i=0; k--) B[1][i][k] = f(B[1][i-1][k],B[1][i][k]); for(int i=h-1; i>=0; i--) for(int k=1; k=0; i--) for(int k=0; k=0; i--) for(int k=w-2; k>=0; k--) B[3][i][k] = f(B[3][i][k],B[3][i][k+1]); for(int i=h-2; i>=0; i--) for(int k=w-1; k>=0; k--) B[3][i][k] = f(B[3][i][k],B[3][i+1][k]); } T rangeans(int a,int b,int c,int d){ //(a,b)を左上,(c,d)を右下の範囲内 a,b<0許可 c,dは範囲内. //assert(a <= c && b <= d && 0 <= c && c < h && 0 <= d && d < w); c = min(h-1,c); d = min(w-1,d); T ret = A.at(c).at(d); if(a > 0) ret = op(ret,inv(A.at(a-1).at(d))); if(b > 0) ret = op(ret,inv(A.at(c).at(b-1))); if(a > 0 && b > 0) ret = op(ret,A.at(a-1).at(b-1)); return ret; } T getA(int x,int y){ //x<0,y<0は許容. assert(x < h && y < w); if(x >= 0 && y >= 0) return A.at(x).at(y); return e(); } T getB(int p,int x,int y){ //同上. assert(0 <= p && p < 4 && x < h && y < w && okB); if(x >= 0 && y >= 0) return B[p].at(x).at(y); return e(); } vector> allA(){return A;} vector> allB(int p){assert(0 <= p && p < 4); return B[p];} }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector> S(N); for(auto &[x,y] : S){ int a,b; cin >> a >> b; a += 999; x = (a+b),y = (a-b); } vector> give(3000,vector(3000)); Cumulative2D Z; int M; cin >> M; while(M--){ int a,b; cin >> a >> b; a += 999; int x = (a+b),y = (a-b); give.at(x).at(y) = 1; } Z.make(give); int low = -1,high = 2001; while(high-low > 1){ int mid = (low+high)/2; bool ok = true; for(auto &[x,y] : S) if(Z.rangeans(x-mid,y-mid,x+mid,y+mid)){ok = false; break;} if(ok) low = mid; else high = mid; } cout << high << endl; }