#P1233. 木棍加工
木棍加工
Description
There are wooden sticks in total, and the length and width of each stick are known. The sticks can be processed by a machine one after another. Before processing a stick, the machine may need setup time. The setup time is defined as follows:
- The setup time for the first stick is minute.
- If the just-processed stick has length and width , then for the next stick with length and width , if and , no setup time is needed; otherwise, minute of setup time is needed.
Compute the minimum total setup time needed to process all sticks. For example, if you have sticks with lengths and widths , the minimum setup time is (process in the order ).
Input Format
The first line contains an integer ().
The second line contains integers: . The values of and do not exceed , and adjacent numbers are separated by spaces.
Output Format
A single line containing one integer: the minimum total setup time required.
5
4 9 5 2 2 1 3 5 1 4
2
Hint
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号