It is a well known fact that Sam is an incredibly talented programmer. However, his teacher Bruce is beginning to have doubts.
To test his suspicions, Bruce drops Sam off in a faraway island of
Right before Bruce leaves to teach Sam's class without him, he tells Sam that he has one chance to tell him the maximum value of treasure chests he can obtain. If he fails to do so, Bruce will leave Sam stranded on the island forever. However, Sam is unable to solve this problem. He passes it on to Daniel, who passes it on to you to solve!
Give that Sam starts at island
Constraints
For all subtasks:
Subtask 1 [20%]
Subtask 2 [30%]
Subtask 3 [50%]
Input Specification
The first line of input will contain the integer
The second line of input will contain
The next
Output Specification
Output one integer representing the maximum amount of treasure Sam can gather. Please note that 64-bit integers may be required for full marks.
Sample Input 1
3
4 8 5
1 2 2
2 3 2
Sample Output 1
17
Explanation for Sample Output 1
Sam's optimal path is
Sample Input 2
5
8 10 4 9 1
1 2 1
1 3 2
2 4 1
2 5 1
Sample Output 2
31
Explanation for Sample Output 2
Sam's optimal path is
Comments
Let's go stuck on USACO silver gang!
:blobweary: