#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> backets; 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) { e.hp -= a.d; //if ( e.hp <= 0 ) {++it; continue;} } ++it; continue; } } signed main() { int n, k; scanf("%d %d", &n, &k); backets.resize(MAX_X / BX + 3); rep(i, n) { Enemy e; scanf("%d %d %d", &e.x, &e.y, &e.hp); e.x += 500; e.y += 500; backets[e.x / BX].emplace_back(e); } for(auto& b : backets) { std::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(MAX_X, a.x + a.w + 1))/BX + 1) { deal(backets[i], a); } } int total = 0; for ( auto& b : backets ) { for ( auto& e : b ) { if ( e.hp > 0 ) total += e.hp; } } cout << total << endl; return 0; }