SnowflakeOA #26
Efficient Deployments
Estimated HardJudge-ready
Topics (AI-labelled)State Machines
Processors are arranged in a chain and deployed one at a time. When processor i is deployed, if 0, 1, or 2 of its neighbors are already deployed, it earns no[i], one[i], or both[i], respectively. The first and last processors have only one neighbor. Maximize the total profit of all processors.
Input
The first line contains n, followed by 3 lines: no, one, and both. 1≤n≤100000, and each profit is in 1..10⁹. Original example 1 wrote both as 0, which conflicts with the constraints; this site's examples use valid positive profits, and the algorithm does not rely on positivity.
Output
Output the single integer required by the problem.
Example 1
Input:
3
2 1 3
4 2 1
1 2 3
Output:
9
Example 2
Input:
2
1 6
2 3
3 2
Output:
8
Example 3
Input:
1
7
100
1000
Output:
7
Example notes
The answers to the three public examples are, in order: 9; 8; 7. The examples were rechecked by independent enumeration, state search, or direct simulation.
Editorial
Loading solution…