#include #include #include #include using namespace std; int solve(int N, int M, vector P, vector XA, vector YA, vector XB, vector YB) { map, int> d; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { d[make_pair(XA[i] - XB[j], YA[i] - YB[j])] += P[i]; } } int ans = 0; for (pair, int> i : d) { ans = max(ans, i.second); } return ans; } int main() { int N, M; cin >> N >> M; vector P(N); for (int i = 0; i < N; ++i) { cin >> P[i]; } vector XA(N), YA(N), XB(M), YB(M); for (int i = 0; i < N; ++i) { cin >> XA[i] >> YA[i]; } for (int i = 0; i < M; ++i) { cin >> XB[i] >> YB[i]; } int res1 = solve(N, M, P, XA, YA, XB, YB); for (int i = 0; i < N; ++i) { XA[i] *= -1; } int res2 = solve(N, M, P, XA, YA, XB, YB); for (int i = 0; i < N; ++i) { XB[i] *= -1; } int res3 = solve(N, M, P, XA, YA, XB, YB); for (int i = 0; i < N; ++i) { XA[i] *= -1; } int res4 = solve(N, M, P, XA, YA, XB, YB); cout << max({ res1, res2, res3, res4 }) << endl; return 0; }