#include using namespace std; using u32 = uint32_t; using u64 = uint64_t; void chmax(int& a, int b){ if(a < b) a = b; } int main(){ int N, M; cin >> N >> M; vector P(N); for(int& p : P) cin >> p; int ans = 0; vector> A(N), B(M); for(auto& [a, b] : A){ cin >> a >> b; a ^= 1u << 31; b ^= 1u << 31; } for(auto& [c, d] : B){ cin >> c >> d; c ^= 1u << 31; d ^= 1u << 31; } auto comp = [](pair a, pair b){ return *reinterpret_cast(&a) < *reinterpret_cast(&b); }; auto equal = [](pair a, pair b){ return *reinterpret_cast(&a) == *reinterpret_cast(&b); }; vector, int>> sortA(N); for(int i = 0; i < N; i++) sortA[i] = {A[i], P[i]}; sort(sortA.begin(), sortA.end(), [&](auto& a, auto& b){ return comp(a.first, b.first); }); for(int i = 0; i < 2; i++){ for(auto& [c, d] : B) c = -c; for(int i = 0; i < 2; i++){ for(auto& [c, d] : B) d = -d; sort(B.begin(), B.end(), comp); // 移動量を固定 for(auto [a, b] : A) for(auto [c, d] : B){ const int dx = a - c, dy = b - d; auto sortB = B; for(auto& [c, d] : sortB){ c += dx; d += dy; } // ソートされていれば重なりが O(N + M) int score = 0, at = 0; for(auto [x, p] : sortA){ while(at < M && comp(sortB[at], x)) at++; if(at == M) break; if(equal(sortB[at], x)){ score += p; at++; } } chmax(ans, score); } } } cout << ans << endl; }