#P3360. 偷天换日
偷天换日
Description
The art museum consists of several exhibition rooms and several corridors. Each corridor either ends at an exhibition room, or splits into two corridors.
Each exhibition room contains several paintings, and each painting has a value. Traversing a corridor and stealing a painting both take time.
The police will arrive at the entrance in seconds. Find the maximum total value you can obtain without being caught.

Input Format
- The first line contains an integer ().
- Starting from the second line, a sequence is given in depth-first order. For each entry, read a pair :
- is the time in seconds to either enter an exhibition room or traverse a corridor.
- If , the corridor leads to an exhibition room containing paintings, followed by pairs , where stealing one painting of value takes seconds.
- If , the corridor splits into two sub-corridors; the descriptions of these two sub-corridors follow immediately in depth-first order.
- Constraints: .
- The numbers of rooms and corridors do not exceed .
- The input is given in depth-first order.
Output Format
Output a single integer, the maximum total value that can be obtained.
50
5 0 10 1 10 1 5 0 10 2 500 1 1000 2 18 1 1000000 4
1500
Hint
Source: adapted.
Translated by ChatGPT 5
京公网安备 11011102002149号