#include using namespace std; #define all(c) ((c).begin()), ((c).end()) #define dump(c) cerr << "> " << #c << " = " << (c) << endl; #define iter(c) __typeof((c).begin()) #define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++) #define REP(i, a, b) for (int i = a; i < (int)(b); i++) #define rep(i, n) REP(i, 0, n) #define mp make_pair #define fst first #define snd second #define pb push_back #define debug( fmt, ... ) \ fprintf( stderr, \ fmt "\n", \ ##__VA_ARGS__ \ ) typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef vector vi; typedef vector vll; typedef vector vvll; typedef vector vvi; typedef vector vd; typedef vector vvd; typedef vector vs; typedef pair pii; typedef pair pll; const int INF = 1 << 29; const double EPS = 1e-10; double zero(double d) { return d < EPS ? 0.0 : d; } templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b ostream &operator<<(ostream &os, const pair &p) { return os << '(' << p.first << ',' << p.second << ')'; } template ostream &operator<<(ostream &os, const vector &a) { os << '['; rep(i, a.size()) os << (i ? " " : "") << a[i]; return os << ']'; } string toString(int i) { stringstream ss; ss << i; return ss.str(); } const int MOD = 1000000007; // a^k ll fpow(ll a, ll k, int M) { ll res = 1ll; ll x = a; while (k != 0) { if ((k & 1) == 1) res = (res * x) % M; x = (x * x) % M; k >>= 1; } return res; } struct prepare { prepare() { cout.setf(ios::fixed, ios::floatfield); cout.precision(8); ios_base::sync_with_stdio(false); } } _prepare; // BIT struct BIT { int n; vi bit; BIT(int n) : n(n), bit(n + 1, 0) { } int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; } } }; // BIT 2x struct BIT2 { int n; vector bit; BIT2(int n, int n2): n(n), bit(n+1, BIT(n2)) { } int sum(int i, int j) { int s = 0; while (i > 0) { s += bit[i].sum(j); i -= i & -i; } return s; } void add(int i, int j, int x) { while (i <= n) { bit[i].add(j, x); i += i & -i; } } }; const int MAX_W = 1010; const int MAX_H = 1010; int conv(int x, int y) { x += 501, y += 501; return (x*MAX_W + y); } int main() { int N, K; cin >> N >> K; vector enemies(N); rep(i, N) { int x, y, hp; cin >> x >> y >> hp; enemies[i] = mp(conv(x,y), hp); } BIT2 bit2(MAX_W, MAX_H); rep(i, K) { int ax, ay, w, h, d; cin >> ax >> ay >> w >> h >> d; ax += 501, ay += 501; bit2.add(ax, ay, d); bit2.add(min(ax+w+1, MAX_W-1), ay, -1 * d); bit2.add(ax, min(ay+h+1, MAX_H-1), -1 * d); bit2.add(min(ax+w+1, MAX_W-1), min(ay+h+1, MAX_H-1), d); } ll ans = 0; rep(i, N) { int xy = enemies[i].first; int x = xy / MAX_W; int y = xy % MAX_H; ans += max(0, enemies[i].second - bit2.sum(x,y)); } cout << ans << endl; return 0; }