/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package security; import java.util.*; /** * * @author cteam087 */ public class Security { public static class Guard { int x, y; Guard(int a, int b) { this.x = a; this.y = b; } } public static class Incident { int x, y; Incident(int a, int b) { this.x = a; this.y = b; } } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner sc = new Scanner(System.in); int N, Q; N = sc.nextInt(); Q = sc.nextInt(); sc.nextLine(); ArrayList al = new ArrayList<>(); ArrayList al2 = new ArrayList<>(); ArrayList al3 = new ArrayList<>(); for (int i = 0; i < N; i++) { al.add(new Guard(sc.nextInt(), sc.nextInt())); sc.nextLine(); } for (int i = 0; i < Q; i++) { al2.add(new Incident(sc.nextInt(), sc.nextInt())); sc.nextLine(); } for (Incident incident : al2) { for (Guard guard : al) { int distanceX, distanceY, steps = 0; distanceX = Math.abs(incident.x - guard.x); distanceY = Math.abs(incident.y - guard.y); if(distanceX > distanceY){ al3.add(distanceX); } else al3.add(distanceY); // while (distanceX != 0 && distanceY != 0) { // if (distanceX > 1 && distanceY > 1) { // steps++; // distanceX--; // distanceY--; // continue; // } // if (distanceX > 1) { // steps++; // distanceX--; // continue; // } // if (distanceY > 1) { // steps++; // distanceY--; // } // } // al3.add(steps); } int min = Integer.MAX_VALUE; for (int i = 0; i < al3.size(); i++) { if (min > al3.get(i)) { min = al3.get(i); } } System.out.println(min); al3.clear(); } } }