Score : $600$ points
In a game called Snuketoon, developed by AtCoder, Inc., the player plays as Snuke to dodge water from water guns.
The platform consists of an infinite number line, and Snuke is at the point $0$ at the beginning of the game.
Starting from the beginning of the game, Snuke can make one of the three moves in each second: move $1$ in the negative direction, move $1$ in the positive direction, or remain still. More formally, if Snuke's position is $p$ at $t$ seconds ($t \geq 0$, $t$ is an integer) from the beginning of the game, his position at $t+1$ seconds can be $p-1$, $p$, or $p+1$.
Snuke takes damage from getting soaked by water guns. The water guns shoot $N$ times, and the $i$-th shot is represented by $T_i$, $D_i$, and $X_i$ as follows.
Takahashi, a pro gamer, wants to minimize the total damage taken by Snuke after the end of the $N$-th shot, to post a tweet on this game. Find the total damage taken by Snuke when the game is played to minimize it.
Input is given from Standard Input in the following format:
$N$ $T_1$ $D_1$ $X_1$ $T_2$ $D_2$ $X_2$ $\vdots$ $T_N$ $D_N$ $X_N$
Print the number of points of damage taken by Snuke when the game is played to minimize it.
3 1 0 3 3 1 0 4 0 6
7
For convenience, let $t$ denote the number of seconds elapsed from the beginning of the game. The optimal course of movements for Snuke until all the shots are done is as follows.
Here, Snuke takes a total of $7$ points of damage, so you should print $7$.
3 1 0 1 6 1 1 8 0 -1
0
5 1 0 1000000000 2 1 -1000000000 3 0 1000000000 4 1 -1000000000 5 0 1000000000
4999999997