#include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef ONLINE_JUDGE //POJ # include # include # include # define mkt make_tuple # define empb emplace_back #endif #ifdef _LOCAL # include "for_local.h" #endif using namespace std; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; #define repi(_I, _B, _E) for(int _I = (_B); (_I) < (_E); ++ (_I)) #define rep(_I, _N) for(int _I = 0; (_I) < (_N); ++ (_I)) #define mkp make_pair #define all(_X) (_X).begin(), (_X).end() inline int scani() { int n; scanf("%d", &n); return n; } int n, k; struct Enemy { int x, y, hp; }; struct Attack { int x, y, w, h, d; }; int const MAX_X = 1001, MAX_Y = 1001; int const BX = 32; //1つのバケツがカバーするxの幅 vector> buckets; bool operator < (Enemy const& lhs, Enemy const& rhs) { return (lhs.y - rhs.y) < 0; } void deal(vector& b, Attack& a) { auto&& lb = lower_bound(all(b), Enemy { 0, a.y, 0 }); auto&& ub = upper_bound(all(b), Enemy { 0, a.y + a.h + 1, 0 }); for ( auto it = lb; it != ub; ) { auto& e = *it; if ( a.x <= e.x && e.x <= a.x + a.w ) { if ( e.hp >= 0 ) { e.hp -= a.d; } } ++it; continue; } } signed main() { int n, k; scanf("%d %d", &n, &k); buckets.resize(MAX_X / BX + 5); for ( auto& b : buckets ) { b.reserve(n / buckets.size()); } rep(ie, n) { int x, y, hp; scanf("%d %d %d", &x, &y, &hp); x += 500; y += 500; buckets[x / BX].push_back(Enemy {x, y, hp}); } for ( auto& b : buckets ) { sort(all(b)); } rep(ia, k) { Attack a; scanf("%d %d %d %d %d", &a.x, &a.y, &a.w, &a.h, &a.d); a.x += 500; a.y += 500; repi(i, a.x / BX, min((a.x + a.w + 1 + BX - 1) / BX, buckets.size())) { deal(buckets[i], a); } } ll total = 0; for ( auto& b : buckets ) { for ( auto& e : b ) { if ( e.hp > 0 ) { total += e.hp; } } } cout << total << endl; return 0; }