Radio Watchtowers

Keep K of N towers on a line and raise their radio powers so each pair of kept towers can talk, minimizing raise cost minus sale income.

Hard9GreedySortingHeapIntervalsNo attempts yetTime limit1sMemory limit256 MB

Problem

The border between Bulgaria and Romania is the Danube. Many people cross the river by boat, so the rescue service built NN watchtowers on the Bulgarian bank. Treat the river as a straight line and the towers as points with integer coordinates on it. Tower ii stands XiX_i meters downstream from the place where the river enters Bulgaria.

Each tower carries one radio, and the radio in tower ii has power PiP_i. Two towers ii and jj communicate directly when the distance between them is at most the sum of the two powers, that is when XiXjPi+Pj|X_i - X_j| \le P_i + P_j.

To cut costs, only KK towers will be kept and the other NKN - K will be sold. Selling tower ii brings in SiS_i, but that tower can no longer be used. Every two of the KK kept towers must communicate directly. When only one tower is kept, the communication requirement is dropped. The current powers may not be enough, so the power of a kept tower can be raised. Raising a power by 11 costs 11.

Choose the NKN - K towers to sell and raise the powers of the kept towers so that the requirement holds. Find the smallest possible value of the money spent on raising powers minus the money earned from the sales.

Input

The first line has two integers NN and KK: the number of towers at the start and the number of towers to keep.

Each of the next NN lines has three integers XiX_i, PiP_i, SiS_i: the position of tower ii, its initial power, and its sale price. The towers are given in increasing order of XiX_i, and no two towers share a position.

Output

Print one integer on a single line: the smallest possible value of the money spent on raising powers minus the money earned from the sales. Print a negative number when the sales bring in more than the raises cost.

Constraints

  • 1KN1000001 \le K \le N \le 100\,000
  • 1Xi,Pi,Si1091 \le X_i, P_i, S_i \le 10^9

Hint

In the first example, keeping towers 1, 3 and 4 is one optimal choice. Raising the power of tower 1 by 1717 and the power of tower 4 by 3131 costs 4848, and selling towers 2 and 5 earns 4+2=64 + 2 = 6. The answer is 486=4248 - 6 = 42.

In the second example, towers 2, 3, 6, 7 and 9 can be kept. Raising the power of tower 7 by 22 and the power of tower 9 by 44 costs 66, and selling towers 1, 4, 5 and 8 earns 4+6+9+11=304 + 6 + 9 + 11 = 30. The answer is 630=246 - 30 = -24, a gain of 2424.