Vincent Massey SS - 2014 Senior Contest #1
When Zihao isn't doing homework, he likes to go out with his gang and
pillage some of the
Unfortunately, Zihao is bound by the CCC (Canadian Constitution of
Criminals) honour code. Firstly, he can only move from one village to
another if the second village is located at a higher position along the
river. Thus, he cannot move backwards. Secondly, Zihao can only pillage
a city if he is on the same side of the river as the city. However,
Zihao can cross the river in his boat at any point and as many times as
he wants. Each time Zihao crosses the river, he must pay a tax of
Input Specification
The first line will contain two space-separated integers
The next
No two villages will be at the same position.
Output Specification
Print the largest possible amount of money Zihao can make by pillaging
the villages with the restrictions stated above. You may assume that the
answer will fit inside of a
Sample Input
4 10
1 10 0
4 15 0
2 17 1
3 10 1
Sample Output
32
Explanation
The optimal solution is to visit and pillage each city in order of
position. You start on the left side of the river. First, pillage the
village at position
Comments