N, K = gets.split.take(2).map(&:to_i) X, Y, HP = N.times.map{ gets.split.take(3).map(&:to_i) }.transpose AX, AY, W, H, D = K.times.map{ gets.split.take(5).map(&:to_i) }.transpose M = 1001 X_MIN, X_MAX = X.minmax Y_MIN, Y_MAX = Y.minmax board = M.times.map { [0] * M } # 座標ごとの総ダメージ K.times{|i| ([X_MIN, AX[i]].max+500..[X_MAX, AX[i]+W[i]].min+500).each{|x| ([Y_MIN, AY[i]].max+500..[Y_MAX, AY[i]+H[i]].min+500).each{|y| board[x][y] += D[i] } } } # 残り体力の合計 ans = 0 N.times{|i| x = X[i] + 500 y = Y[i] + 500 ans += [HP[i] - board[x][y], 0].max } p ans