eolymp
bolt
Try our new interface for solving problems
Problems

Divide and conquer

Divide and conquer

Mansur plays the new computer strategic game. The main task in such games is mining resources. Fortunately in this game only one resource is necessary for development --- the gold, and also there is one supplementary resource type - energy. In this game there are mining camps, which provide certain amount of gold and energy. Аll camps are located along the straight line. To protect the mining camps one can build a forcefield (a closed line segment containing mining camps), which needs energy amount equal to it’s length. Mansur wants to build one forcefield in such way, that energy of protected mining camps is enough for the forcefield, and amount of gold provided by these mining camps is maximal possible. Write a program to help Mansur find the maximal amount of gold which he can obtain from protected mining camps. \InputFile First line contains one integer $n~(1 \le n \le 10^5)$ --- number of mining camps. Following $n$ lines contain three space separated integers $x_i, g_i, d_i~(0 \le x_i \le 10^9, 1 \le g_i \le 10^9, 1 \le d_i \le 10^9)$ --- mine coordinates, amount of gold and energy provided by the mine. All $x_i$ are different and given in increasing order. \OutputFile Output only one number --- maximal amount of gold which Mansur can mine.
Time limit 1 second
Memory limit 128 MiB
Input example #1
4
0 5 1
1 7 2
4 4 1
7 15 1
Output example #1
16
Source 2014 X Zhautykov Olympiad Almaty, Kazakhstan, January 12-18