using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class YUKICODER1 { static public int numberOfRandomCases = 0; static public void MakeTestCase(List _input, List _output, ref Func _outputChecker) { } static public void Solve() { var N = NN; var K = NN; var XYHP = Repeat(0, N).Select(_ => new { X = NN, Y = NN, HP = NN }).ToArray(); var AXAYWHD = Repeat(0, K).Select(_ => new { AX = NN, AY = NN, W = NN, H = NN, D = NN }).ToArray(); var seg = new LIB_DualSegTree2D(1501, 1501, 0, (x, y) => x + y); foreach (var item in AXAYWHD) { seg.Update(item.AX + 500, item.AX + 500 + item.W + 1, item.AY + 500, item.AY + 500 + item.H + 1, item.D); } var ans = 0L; foreach (var item in XYHP) { var dam = seg[item.X + 500, item.Y + 500]; ans += Max(0, item.HP - dam); } Console.WriteLine(ans); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable OrderByRand(this IEnumerable x) => x.OrderBy(_ => xorshift); static long Count(this IEnumerable x, Func pred) => Enumerable.Count(x, pred); static IEnumerable Repeat(T v, long n) => Enumerable.Repeat(v, (int)n); static IEnumerable Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IEnumerable OrderBy(this IEnumerable x) => x.OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IEnumerable OrderBy(this IEnumerable x, Func selector) => x.OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IEnumerable OrderByDescending(this IEnumerable x) => x.OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IEnumerable OrderByDescending(this IEnumerable x, Func selector) => x.OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator _xsi = _xsc(); static IEnumerator _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_DualSegTree2D where T : IEquatable { int xsz; int ysz; T ti; Func f; T[,] dat; [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_DualSegTree2D(long _xsz, long _ysz, T _ti, Func _f) { xsz = 1; ysz = 1; while (xsz < _xsz) xsz <<= 1; while (ysz < _ysz) ysz <<= 1; ti = _ti; f = _f; dat = new T[xsz << 1, ysz << 1]; for (var i = 0; i < xsz; ++i) for (var j = 0; j < ysz; ++j) dat[i, j] = ti; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(long xl, long xr, long yl, long yr, T v) { if (xl == xr || yl == yr) return; if (xr < xl || yr < yl) throw new Exception(); for (long xli = xsz + xl, xri = xsz + xr; xli < xri; xli >>= 1, xri >>= 1) { if ((xli & 1) == 1) { for (long yli = ysz + yl, yri = ysz + yr; yli < yri; yli >>= 1, yri >>= 1) { if ((yli & 1) == 1) { dat[xli, yli] = f(dat[xli, yli], v); ++yli; } if ((yri & 1) == 1) { --yri; dat[xli, yri] = f(dat[xli, yri], v); } } ++xli; } if ((xri & 1) == 1) { --xri; for (long yli = ysz + yl, yri = ysz + yr; yli < yri; yli >>= 1, yri >>= 1) { if ((yli & 1) == 1) { dat[xri, yli] = f(dat[xri, yli], v); ++yli; } if ((yri & 1) == 1) { --yri; dat[xri, yri] = f(dat[xri, yri], v); } } } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] void EvalY(long x, long y) { if (y < 1) return; EvalY(x, y >> 1); if (dat[x, y].Equals(ti)) return; if (y < ysz) { dat[x, (y << 1) | 0] = f(dat[x, (y << 1) | 0], dat[x, y]); dat[x, (y << 1) | 1] = f(dat[x, (y << 1) | 1], dat[x, y]); dat[x, y] = ti; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] void EvalXY(long x, long y) { if (x < 1) return; EvalXY(x >> 1, y); EvalY(x, y); if (dat[x, y].Equals(ti)) return; if (x < xsz) { dat[(x << 1) | 0, y] = f(dat[(x << 1) | 0, y], dat[x, y]); dat[(x << 1) | 1, y] = f(dat[(x << 1) | 1, y], dat[x, y]); dat[x, y] = ti; } } public T this[long x, long y] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { EvalXY(x += xsz, y += ysz); return dat[x, y]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] set { EvalXY(x += xsz, y += ysz); dat[x, y] = value; } } } class LIB_FastIO { public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue param = new Queue(); string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } public LIB_FastIODebug() { } public override string Scan() => NextString(); public override long Long() => long.Parse(NextString()); public override double Double() => double.Parse(NextString()); } }