#P9541. 「AWOI Round 2 D」数字三角形
「AWOI Round 2 D」数字三角形
Problem Description
Glad found a number triangle with layers. He found that he can use magic to manipulate this triangle.
First, he can spend cost points to rotate the triangle times. Here, a “rotation” means rotating clockwise around the center of the triangle.
Then, he can repeatedly perform the following operation:
- Spend cost point, choose one layer, and swap the positions of any two numbers in that layer.
Now, Glad wants to walk from the last layer of the triangle to the very top. The starting point can be any number in the last layer. Each step can only move to a number adjacent to the current number, and in each row he can pass through at most one number.
Glad wants to minimize the total cost points consumed under the condition that the sum of the numbers he passes through is maximized. Can you help him?
Input Format
A positive integer , representing the number of layers of the triangle.
The next lines describe the number triangle. The -th layer has numbers ().
Output Format
Two integers, representing the maximum possible sum of the numbers that can be passed through, and the minimum total cost points that must be spent.
5
1
2 3
4 5 6
10 9 8 7
2 5 2 5 6
40 10
Hint
Sample Explanation
The initial triangle is:
1
2 3
4 5 6
10 9 8 7
2 5 2 5 6
Rotate it to the right times, costing cost points. The triangle becomes:
6
7 5
6 8 2
3 5 9 5
1 2 4 10 2
Without any swaps, walking along yields the maximum value , and the total cost is cost points.
Constraints
This problem uses bundled testdata.
| Subtask ID | Constraints | Special Property | Score |
|---|---|---|---|
| AB | |||
| A | |||
| B | |||
| None | |||
Special Property A: An optimal solution can be obtained without swapping numbers.
Special Property B: An optimal solution can be obtained without rotating to the right.
For of the testdata, it is guaranteed that and .
Staff
| S__X | I_am_AKed_by_NOI | ||
Translated by ChatGPT 5