Disjoint-Sparse-Table Optimization
시간 제한2초메모리 제한1024 MB
1부터 2Q까지의 점을 잇는 Q개의 구간과 가중치 배열이 주어질 때, 각 구간을 직접 사거나 내부 한 점에서 두 구간으로 쪼개 사는 조건을 만족하는 최소 비용 집합을 찾는다.
문제
You are given an integer sequence of length and intervals . Here, , satisfy , and each integer between and appears once as an end of an interval.
Your goal is to create a set of intervals to satisfy at least one of the following conditions for all .
- There exists an integer () such that and .
The cost of the set is defined as follows.
The sum of for all intervals included in .
Find the minimum cost of the set that satisfies the condition.
입력
출력
Output the minimum cost of the set that satisfies the condition. Add a new line at the end of the output.
제한
- All inputs consist of integers.
- Each integer from to appears in .
힌트
In Sample Input 1, the optimal set is , where the cost is .