#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } constexpr int B = 32; ll HP[1005][1005], lazy[35][35]; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, K, X, Y, W, H, D; cin >> N >> K; for(int i = 0; i < N; ++i){ cin >> X >> Y; X += 500; Y += 500; cin >> HP[X][Y]; } for(int q = 0; q < K; ++q){ cin >> X >> Y >> W >> H >> D; X += 500; Y += 500; if(W < B * 2 || H < B * 2){ for(int x = X; x <= min(1000, X + W); ++x){ for(int y = Y; y <= min(1000, Y + H); ++y){ HP[x][y] -= D; } } continue; } int lx = X, rx = min(1000, X + W) + 1; while(lx < rx && lx % B != 0){ int ly = Y, ry = min(1000, Y + H) + 1; while(ly < ry && ly % B != 0){ HP[lx][ly++] -= D; } while(ly < ry && ry % B != 0){ HP[lx][--ry] -= D; } ++lx; } while(lx < rx && rx % B != 0){ --rx; int ly = Y, ry = min(1000, Y + H) + 1; while(ly < ry && ly % B != 0){ HP[rx][ly++] -= D; } while(ly < ry && ry % B != 0){ HP[rx][--ry] -= D; } } int ly = Y, ry = min(1000, Y + H) + 1; while(ly < ry && ly % B != 0) ++ly; while(ly < ry && ry % B != 0) --ry; for(int i = lx / B; i < rx / B; ++i){ for(int j = ly / B; j < ry / B; ++j){ lazy[i][j] += D; } } } ll ans = 0; for(int x = 0; x <= 1000; ++x){ for(int y = 0; y <= 1000; ++y){ ans += max(0LL, HP[x][y] - lazy[x / B][y / B]); } } cout << ans << endl; return 0; }