eolymp
bolt
Try our new interface for solving problems

Points

John is a fan of amusement parks. He goes every weekend and plays different games. This weekend he found a challenging one - it is a target shooting game. The targets are placed along a straight line. For all target positions \textbf{i}(assume the target numbering goes from right to left), there are three possible points that John can win if he chooses that target: \textbf{a_i}, if there are no neighbor targets chosen, \textbf{b_i} if one neighbor, and \textbf{c_i} if two neighbors. Could you help John choose the targets in order to maximize the number of points he can win? \InputFile The program input is from a text file. It starts with the number \textbf{n} (\textbf{n} < \textbf{1000000}) of targets. Follows the values of \textbf{a_i}, \textbf{b_i}, and \textbf{c_i} for each target \textbf{i}. The program prints the maximum number of points John can win. The input data are correct and terminate with an end of file. \OutputFile The program prints the result to the standard output from the beginning of a line. \textit{\textbf{Note}}: Input/output samples are in the table below. There are two tests. Each consists of only one target. For the first one \textbf{n=1}, \textbf{a_1=3}, \textbf{b_1=0}, \textbf{c_1=0}, and the maximum number of points is \textbf{3}. For the second one \textbf{n=1}, \textbf{a_1=1}, \textbf{b_1=2}, \textbf{c_1=3}, and the maximum number of points is 1.The result consists of the maximum number of points John can win, printed from the beginning of the line.
Zaman məhdudiyyəti 0.5 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
1
3 0 0
Çıxış verilənləri #1
3
Mənbə ACM SEERC 2013, SouthEastern European Region, October, 12/10/2013, Vinnica & Bucharest