logo AlgoBeat OnlineJudge
登录 注册

#215773. [JAG 2023 Summer Camp #2] Disjoint-Sparse-Table Optimization

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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.

输入格式

The input satisfies the following constraints.

  • All inputs consist of integers.
  • Each integer from to appears in .

输出格式

Output the minimum cost of the set that satisfies the condition. Add a new line at the end of the output.

样例

样例输入 1

3
1 4
2 5
3 6
1 2 3 4 5

样例输出 1

20

样例输入 2

5
3 7
1 10
5 9
4 8
2 6
6 4 8 5 9 8 9 8 2

样例输出 2

132

数据范围与提示

In Sample Input 1, the optimal set is , where the cost is .