#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define CLEAR(d) memset((d), 0, (sizeof((d)))) #define ALL(c) (c).begin(), (c).end() #define SORT(x) sort((x).begin(), (x).end()) #define RSORT(x) sort((x).begin(), (x).end(), greater() ) #define SIZE(a) ((int)((a).size())) #define MAX3(a, b, c) (max(max((a), (b)), (c))) #define MIN3(a, b, c) (min(min((a), (b)), (c))) #define MP make_pair #define PB push_back #define MOD 1000000007 #define EPS 1e-5 #define PI (acos(-1)) #define INF 10000000 struct edge{ int to, cost; }; //=================================================== int damage[1001][1001]; int main() { int n, k, ax, ay, w, h, d, sum = 0; cin >> n >> k; vector x(n), y(n), hp(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i] >> hp[i]; } for (int i = 0; i < k; i++) { cin >> ax >> ay >> w >> h >> d; ax += 500, ay += 500; damage[ay][ax] += d; if (ay + h + 1 <= 1000) { damage[ay + h + 1][ax] -= d; } if (ax + w + 1 <= 1000) { damage[ay][ax + w + 1] -= d; } if (ay + h + 1 <= 1000 && ax + w + 1 <= 1000) { damage[ay + h + 1][ax + w + 1] += d; } } for (int y = 0; y <= 1000; y++) { for (int x = 1; x <= 1000; x++) { damage[y][x] += damage[y][x - 1]; } } for (int x = 0; x <= 1000; x++) { for (int y = 1; y <= 1000; y++) { damage[y][x] += damage[y - 1][x]; } } for (int i = 0; i < n; i++) { int h = hp[i] - damage[y[i] + 500][x[i] + 500]; sum += (h >= 0) ? h : 0; } printf("%d\n", sum); return 0; }