AtCoder Regular Contest 147
翻译中…
Problem Statement
翻译中…
$N$ people, numbered $1,2,\ldots ,N$, are going to stand on the number line. Let's denote by $x_i$ the coordinate the Person $i$ stands at. Then, $x_i$ should be an integer satisfying $L_i \leq x_i \leq R_i$. Multiple people can occupy the same coordinate.
翻译中…
We define the dissatisfaction level as the following formula:
翻译中…
$\displaystyle\sum_{i=1}^{N-1}\sum_{j=i+1}^{N}|x_j-x_i|$
翻译中…
Find the minimum possible value of the dissatisfaction level.
翻译中…
Constraints
翻译中…
$2 \leq N \leq 3 \times 10^5$$1 \leq L_i \leq R_i \leq 10^7 \,(1 \leq i \leq N)$- All values in input are integers.
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
N
L_1 R_1
L_2 R_2
\vdots
L_N R_N
翻译中…
Output
翻译中…
Print the answer.
翻译中…
样例
Input #1
3
1 3
2 4
5 6
Output #1
4
If we let $x_1=3,x_2=4,x_3=5$, we get the dissatisfaction level of $4$. We cannot make it $3$ or less, so the answer is $4$.
Input #2
3
1 1
1 1
1 1
Output #2
0
Input #3
6
1 5
2 4
1 1
4 4
3 6
3 3
Output #3
15
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。