#include #include #include #include #include #include using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<(n);i++) const int INF = 1e9; //2次元BIT const int MAX_W = 1000, MAX_H = 1000; int bit[MAX_W + 1][MAX_H + 1]; void add(int a, int b, ll w){ for (int y = a; y < MAX_W; y += y & -y){ for (int x = b; x < MAX_H; x += x & -x){ bit[y][x] += w; } } } ll sum(int a, int b){ ll ret = 0; for (int y = a; y > 0; y -= y & -y){ for (int x = b; x > 0; x -= x & -x){ ret += bit[y][x]; } } return ret; } int n, k; int x[100010], y[100010], hp[100010]; int main(void){ cin >> n >> k; rep(i, n){ cin >> x[i] >> y[i] >> hp[i]; x[i] += 500; y[i] += 500;// 0を500に } rep(i, k){ int ax, ay, w, h, d; cin >> ax >> ay >> w >> h >> d; ax += 500; ay += 500; add(ay, ax, d); add(ay + h + 1, ax, -d); add(ay, ax + w + 1, -d); add(ay + h + 1, ax + w + 1, d); } ll ans = 0; rep(i, n){ ans += max((ll)0, hp[i] - sum(y[i], x[i])); } printf("%lld\n", ans); return 0; }