NOMURA プログラミングコンテスト 2021 (AtCoder Regular Contest 121)
B
RGB Matching
AtCoder
⌀ 1159
原题
← AC →
翻译中…

Problem Statement

翻译中…

Snuke has $2N$ dogs, numbered $1$ through $2N$.

翻译中…

The cuteness of Dog $i$ is $a_i$. The color of Dog $i$ is $c_i$, which is R, G, or B; R stands for red, G stands for green, and B stands for blue.

翻译中…

Snuke has $N$ kennels, and wants to put two dogs in each kennel. Note that this means each dog will be in exactly one kennel.

翻译中…

When he puts two dogs in the same kennel, it will cause some dissatisfaction in that kennel. The level of dissatisfaction is represented as an integer. When Dogs $i$ and $j$ are in the same kennel, the dissatisfaction will be $0$ if $c_i = c_j$ and $|a_i - a_j|$ otherwise.

翻译中…

Find the minimum possible total dissatisfaction when putting two dogs in each of the $N$ kennels.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 10^{5}$
  • $1 \leq a_i \leq 10^{15}$
  • $a_i$ is an integer.
  • $c_i$ is R, G, or B.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
a_{1} c_{1}
\vdots
a_{2N} c_{2N}

翻译中…

Output

翻译中…

Print the minimum possible total dissatisfaction when putting two dogs in each of the $N$ kennels.

翻译中…

样例

Input #1
1
1 R
2 G
Output #1
1
- Dog $1$ has the cuteness of $1$, and Dog $2$ has the cuteness of $2$. - Since $c_1 \neq c_2$, the dissatisfaction will be $1$.
Input #2
1
1 B
2 B
Output #2
0
- Dog $1$ has the cuteness of $1$, and Dog $2$ has the cuteness of $2$. - Since $c_1 = c_2$, the dissatisfaction will be $0$.
Input #3
10
585 B
293 B
788 B
222 B
772 G
841 B
115 R
603 G
450 B
325 R
851 B
205 G
134 G
651 R
565 R
548 B
391 G
19 G
808 B
475 B
Output #3
0
题目信息
题号
arc121_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。