This page is still under construction.

Parts of this page are still being built. What you see may change.

Delivering Problem Sheets

Time limit2sMemory limit1024 MB

Summary
Given N points and Q query points in 11 dimensions, report for each query the maximum Manhattan distance to any of the N points.
Level

Medium6 of 10

Topics
Math, Bit manipulation, Brute force, Implementation
Solved
No attempts yet

Problem

Gyo-jun felt unsatisfied with the online SNUPC 2020, so he decided to deliver the problem sheets directly to the homes of the NN contest participants.

As you know, this universe has 11 dimensions, so a participant's home is a point in 11-dimensional coordinates, x=(x1,x2,⋯ ,x11)\mathbf{x} = (x_{1}, x_{2}, \cdots, x_{11}). To move around in this universe you have to use the roads that run along the coordinate axes, so the distance needed to travel between two points x\mathbf{x} and y\mathbf{y} is as follows.

dist(x,y)=∑k=111∣xk−yk∣\mathrm{dist}(\mathbf{x},\mathbf{y}) = \sum_{k=1}^{11} \lvert x_{k} - y_{k} \rvert

Gyo-jun will park the car carrying the problem sheets in one place and then deliver them. The 11-dimensional world has QQ parking lots, and a parking lot is also a point in the 11-dimensional coordinate system, y=(y1,⋯ ,y11)\mathbf{y} = (y_{1}, \cdots, y_{11}).

Carrying the problem sheets by hand is hard, so for each parking lot location Gyo-jun wants to know the distance to the farthest participant's home. He thought this problem was not bad, so he is going to write it on the problem sheet too and bring it to you.

Input

The first line of the input gives the number of participants NN and the number of parking lots QQ, separated by a space.

Each of the next NN lines gives the coordinates of a participant's home, (xi,1,⋯ ,xi,11)(x_{i,1}, \cdots, x_{i,11}). Specifically, line (i+1)(i+1) gives the 1111 integers xi,1x_{i,1}, ⋯\cdots, xi,11x_{i,11} that represent the coordinates of participant ii's home, separated by spaces.

Each of the QQ lines starting from line N+2N+2 gives the coordinates of a parking lot, (yi,1,⋯ ,yi,11)(y_{i,1}, \cdots, y_{i,11}). Specifically, line (N+1+i)(N+1+i) gives the 1111 integers yi,1y_{i,1}, ⋯\cdots, yi,11y_{i,11} that represent the coordinates of parking lot ii, separated by spaces.

Output

Print the answers over QQ lines. On line ii, print the distance from parking lot ii to the farthest participant's home.

Constraints

  • 1≤N,Q≤50,0001 \le N, Q \le 50,000
  • −109≤xi,j,yi,j≤109-10^{9} \le x_{i, j}, y_{i, j} \le 10^{9} (1≤i≤N,1≤j≤11)(1 \le i \le N, 1 \le j \le 11)

Examples1

  1. Example 1

    Input
    2 2
    0 1 2 3 4 5 6 7 8 9 10
    0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10
    3 8 -4 2 4 6 0 -9 5 2 7
    10 34 2 -38 17 55 -23 30 -19 41 22
    
    Expected output
    87
    312