module main; // https://mmxsrup.hatenablog.com/entry/2016/09/30/154952 より // いもす法 import std; void main() { int N, K; readln.chomp.formattedRead("%d %d", N, K); auto X = new int[](N), Y = new int[](N), HP = new int[](N); foreach (ref x, ref y, ref hp; lockstep(X, Y, HP)) { readln.chomp.formattedRead("%d %d %d", x, y, hp); x += 500, y += 500; } auto imos = new int[][](1510, 1510); foreach (_; 0 .. K) { int ax, ay, w, h, d; readln.chomp.formattedRead("%d %d %d %d %d", ax, ay, w, h, d); ax += 500, ay += 500; // 左上 imos[ay][ax] += d; // 右上 imos[ay][ax + w + 1] -= d; // 左下 imos[ay + h + 1][ax] -= d; // 右下 imos[ay + h + 1][ax + w + 1] += d; } // 横方向の累積和 foreach (i; 0 .. 1505) foreach (j; 0 .. 1505) imos[i][j + 1] += imos[i][j]; // 縦方向の累積和 foreach (i; 0 .. 1505) foreach (j; 0 .. 1505) imos[i + 1][j] += imos[i][j]; long ans = 0; foreach (y, x, hp; lockstep(Y, X, HP)) ans += max(0L, hp - imos[y][x]); writeln(ans); }