#include #define show(x) cout << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template constexpr T INF = numeric_limits::max() / 100; constexpr ll HALF = 500; constexpr ll MAX = HALF * 2; ll imos[MAX + 1][MAX + 1]; ll sum[MAX + 1][MAX + 1]; struct Enemy { Enemy() = default; Enemy(ll hp, ll x, ll y) : hp(hp), x(x), y(y) {} ll hp; ll x; ll y; }; int main() { ll N, K; cin >> N >> K; vector enemy(N); for (ll i = 0; i < N; i++) { ll x, y, hp; cin >> x >> y >> hp; enemy[i] = Enemy{hp, x + HALF, y + HALF}; } for (ll i = 0; i < K; i++) { ll ax, ay, w, h, d; cin >> ax >> ay >> w >> h >> d; const ll starty = ay + HALF; const ll endy = min(ay + h + HALF, MAX); const ll startx = ax + HALF; const ll endx = min(ax + w + HALF, MAX); //// 1次元imos // for (ll y = starty; y <= endy; y++) { // imos[y][startx] += d; // if (endx < MAX) { // imos[y][endx + 1] -= d; // } // } // 2次元imos imos[starty][startx] += d; if (endx < MAX) { imos[starty][endx + 1] -= d; } if (endy < MAX) { imos[endy + 1][startx] -= d; if (endx < MAX) { imos[endy + 1][endx + 1] += d; } } } //// i次元imos // for (ll y = 0; y <= MAX; y++) { // sum[y][0] = imos[y][0]; // } // for (ll y = 0; y <= MAX; y++) { // for (ll x = 1; x <= MAX; x++) { // sum[y][x] = sum[y][x - 1] + imos[y][x]; // } // } // 二次元imos for (ll y = 0; y <= MAX; y++) { sum[y][0] = imos[y][0]; } for (ll y = 0; y <= MAX; y++) { for (ll x = 1; x <= MAX; x++) { sum[y][x] = sum[y][x - 1] + imos[y][x]; } } for (ll x = 0; x <= MAX; x++) { for (ll y = 1; y <= MAX; y++) { sum[y][x] += sum[y - 1][x]; } } ll res = 0; for (ll i = 0; i < N; i++) { const ll hp = enemy[i].hp; const ll y = enemy[i].y; const ll x = enemy[i].x; if (sum[y][x] < hp) { res += (hp - sum[y][x]); } } cout << res << endl; return 0; }