output_description: Print the maximum possible sum of the values of the blocks contained in the
  tower.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      w_1 s_1 v_1
      w_2 s_2 v_2
      :
      w_N s_N v_N
attempt: import sys
  
  input = sys.stdin.readline
  N, M = map(int, input().split())
  
  N0 = 2 ** ((N + 1).bit_length())
  INF = 10**18
  data = [0] * (2 * N0)
  lazy = [0] * (2 * N0)
  
  
  def gindex(l, r):
      L = l + N0
      R = r + N0
      lm = (L // (L & -L)) >> 1
      rm = (R // (R & -R)) >> 1
      while L < R:
          if R <= rm:
              yield R
          if L <= lm:
              yield L
          L >>= 1
          R >>= 1
      while L:
          yield L
          L >>= 1
  
  
  def propagates(*ids):
      for i in reversed(ids):
          v = lazy[i - 1]
          if not v:
              continue
          lazy[2 * i - 1] += v
          lazy[2 * i] += v
          data[2 * i - 1] += v
          data[2 * i] += v
          lazy[i - 1] = 0
  
  
  def update(l, r, x):
      L = N0 + l
      R = N0 + r
      while L < R:
          if R & 1:
              R -= 1
              lazy[R - 1] += x
              data[R - 1] += x
          if L & 1:
              lazy[L - 1] += x
              data[L - 1] += x
              L += 1
          L >>= 1
          R >>= 1
  
      for i in gindex(l, r):
          data[i - 1] = max(data[2 * i - 1], data[2 * i]) + lazy[i - 1]
  
  
  def update2(k, x):
      k += N0 - 1
      data[k] = x
      while k >= 0:
          k = (k - 1) // 2
          data[k] = max(data[2 * k + 1], data[2 * k + 2])
  
  
  def query(l, r):
      propagates(*gindex(l, r))
      L = N0 + l
      R = N0 + r
      s = -INF
      while L < R:
          if R & 1:
              R -= 1
              s = max(s, data[R - 1])
          if L & 1:
              s = max(s, data[L - 1])
              L += 1
          L >>= 1
          R >>= 1
      return s
  
  
  xs = [0] * (N + 1)
  ys = [[] for _ in range(N + 1)]
  for _ in range(M):
      l, r, a = map(int, input().split())
      xs[l] += a
      ys[r].append((l, a))
  
  for i in range(1, N + 1):
      update(0, i, xs[i])
      update2(i, query(0, i))
      for l, a in ys[i]:
          update(0, l, -a)
  print(query(0, N + 1))
  
problem_description: Statement
  
  There are N blocks, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
  Block i has a weight of w_i, a solidness of s_i and a value of v_i.
  
  Taro has decided to build a tower by choosing some of the N blocks and
  stacking them vertically in some order. Here, the tower must satisfy the
  following condition:
  
    * For each Block i contained in the tower, the sum of the weights of the blocks stacked above it is not greater than s_i.
  
  Find the maximum possible sum of the values of the blocks contained in the
  tower.
samples: [{"input": "3\n    2 2 20\n    2 1 30\n    3 1 40", "output": "50\n    \n\nIf Blocks 2, 1 are stacked in this order from top to bottom, this tower will\nsatisfy the condition, with the total value of 30 + 20 = 50.\n\n* * *"}, {"input": "4\n    1 2 10\n    3 1 10\n    2 4 10\n    1 6 10", "output": "40\n    \n\nBlocks 1, 2, 3, 4 should be stacked in this order from top to bottom.\n\n* * *"}, {"input": "5\n    1 10000 1000000000\n    1 10000 1000000000\n    1 10000 1000000000\n    1 10000 1000000000\n    1 10000 1000000000", "output": "5000000000\n    \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "8\n    9 5 7\n    6 2 7\n    5 7 3\n    7 8 8\n    1 9 6\n    3 3 3\n    4 1 7\n    4 5 5", "output": "22\n    \n\nWe should, for example, stack Blocks 5, 6, 8, 4 in this order from top to\nbottom."}]