Under construction

Still being built. Things may change

Cookie-Loving Chunbae

Interview

Time limit1sMemory limit1024 MB

Summary
Each cookie has a position, a cost, and a free-range radius, and the task asks for the cheapest set of purchases whose ranges together cover all K cookies.
Level

Medium6 of 10

Topics
Dynamic programming, Segment tree, Intervals
Solved
No attempts yet

Problem

Chunbae ate every cookie at home again today. When Siwon tells him about an event at a cookie shop, he decides to go.

The shop has KK cookies on a display shelf of NN cells. Cookie ii is in cell XiX_i and costs CiC_i won. The cookies are all in different positions.

Because the shop is running an event, if Chunbae buys cookie ii, the shop gives him, for free, any cookies he wants among those whose distance from cookie ii is at most RiR_i. The distance between cookies ii and jj is ∣Xi−Xj∣|X_i - X_j|.

Chunbae is broke after buying a MacBook, and he wants to eat all KK cookies at the lowest cost. Find the minimum amount he must pay, by buying cookies or receiving them for free, to get all KK cookies.

Input

The first line contains the shelf length NN and the number of cookies KK, separated by a space. (1≤K≤N≤100 000)(1 \le K \le N \le 100\,000)

From the second line on, the next KK lines each contain XiX_i, RiR_i, and CiC_i, separated by spaces. (1≤Xi≤N,0≤Ri≤N,1≤Ci≤1 000)(1 \le X_i \le N, 0 \le R_i \le N, 1 \le C_i \le 1\,000)

Output

Print the minimum amount that must be paid to buy all cookies.

Examples1

  1. Example 1

    Input
    10 3
    3 3 2
    5 1 8
    9 1 1
    
    Expected output
    3