import std.stdio; import std.conv; import std.string; import std.algorithm; import std.array; import std.range; void main(){ int n, k; readf("%d %d\n", &n, &k); auto enemy = new int[3][n + 5]; auto atack = new int[5][k + 5]; auto matrix = new int[1005][1005]; foreach(i; 0..n){ enemy[i] = readln.split.map!(to!int).array; } foreach(i; 0..k){ atack[i] = readln.split.map!(to!int).array; } foreach(a; atack){ matrix[a[1] + 500][a[0] + 500] += a[4]; matrix[a[1] + 500][a[0] + a[2] + 1 + 500] -= a[4]; matrix[a[1] + a[3] + 1 + 500][a[0] + 500] -= a[4]; matrix[a[1] + a[3] + 1 + 500][a[0] + a[2] + 1 + 500] += a[4]; } foreach(y; 0..1000){ foreach(x; 1..1000){ matrix[y][x] += matrix[y][x-1]; } } foreach(y; 1..1000){ foreach(x; 0..1000){ matrix[y][x] += matrix[y-1][x]; } } int[] rest; foreach(e; enemy){ rest ~= max(0, e[2] - matrix[e[1]+500][e[0]+500]); } // foreach(y; 500..510){ // foreach(x; 500..510){ // write(matrix[y][x], " "); // } // writeln; // } rest.reduce!("a + b").writeln; }