#P3162. [CQOI2012] 组装

    ID: 2211 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学贪心2012重庆各省省选排序

[CQOI2012] 组装

Description

There are mm production workshops on the number line that can produce parts. There are nn types of parts, numbered 1n1 \sim n. The ii-th workshop is located at coordinate xix_i and produces part type pip_i (1pin1 \le p_i \le n). You need to build an assembly workshop at some position on the number line to assemble these parts. To minimize transportation cost, you need to minimize \, cost1+cost2++costncost_1 + cost_2 + \ldots + cost_n, where costxcost_x denotes the minimum squared distance from the assembly workshop to any workshop that produces part type xx.

Input Format

The first line contains two integers nn, mm, the number of part types and the number of production workshops. Each of the following mm lines contains two integers xix_i and pip_i (1pin1 \le p_i \le n). The input is ordered from left to right by workshop position (i.e., xixi+1x_i \le x_{i+1}; note that positions may repeat). It is guaranteed that every part type has at least one workshop producing it.

Output Format

Output a single line: the optimal location of the assembly workshop (it may coincide with a production workshop), rounded to four decimal places. It is guaranteed that the optimal location is unique.

3 5
-1 3
0 1
2 3
4 2
5 2
2.0000

Hint

  • Test points 1–4: n15n \le 15, m25m \le 25, xi100x_i \le 100.
  • Test points 5–10: n104n \le 10^4, m105m \le 10^5, xi105x_i \le 10^5.

Translated by ChatGPT 5