using System; using System.Linq; class Program { public static void Main(string[] args) { var first = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var enemies = new long[1001,1001]; int n = first[0]; int k = first[1]; const int offset = 500; for (int i = 0; i < n; i++) { var enemy = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); enemies[enemy[0] + offset, enemy[1] + offset] = enemy[2]; } var attacks = new long[1001, 1001]; for (int j = 0; j < k; j++) { var attack = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var left = attack[0] + offset; var top = attack[1] + offset; var right = left + attack[2] + 1; right = Math.Min(1000, right); var bottom = top + attack[3] + 1; bottom = Math.Min(1000, bottom); for (int y = top; y < bottom; y++) { attacks[left, y] += attack[4]; if (right == 1000) { if (y < 1000) { attacks[0, y + 1] -= attack[4]; } } else { attacks[right, y] -= attack[4]; } } } long current = 0; long sum = 0; for (int y = 0; y < 1001; y++) { for (int x = 0; x < 1001; x++) { current += attacks[x, y]; if (current < enemies[x, y]) { sum += enemies[x, y] - current; } } } Console.WriteLine(sum); } }