#include #include #include #include using namespace std; using pint = pair; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; } template pair operator-(const pair &l, const pair &r) { return make_pair(l.first - r.first, l.second - r.second); } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector P(N); for (auto &x : P) cin >> x; vector AB(N), CD(M); for (auto &[x, y] : AB) cin >> x >> y; for (auto &[x, y] : CD) cin >> x >> y; int ret = 0; vector> vs(N * M); REP(t, 2) { REP(tt, 2) { REP(i, N) REP(j, M) { vs[i * M + j] = {CD[j] - AB[i], P[i]}; } sort(vs.begin(), vs.end()); int c = 0; REP(k, vs.size()) { c += vs[k].second; chmax(ret, c); if (k + 1 < int(vs.size()) and vs[k].first != vs[k + 1].first) c = 0; } REP(i, N) AB[i].second *= -1; } REP(i, N) AB[i].first *= -1; } cout << ret << '\n'; }