AtCoder Regular Contest 142
翻译中…
Problem Statement
翻译中…
There are $N$ wizards, numbered $1, \ldots, N$.
Wizard $i$ has a strength of $a_i$ and plans to defeat a monster with a strength of $b_i$.
翻译中…
You can perform the following operation any number of times.
翻译中…
- Increase the strength of any wizard of your choice by
$1$.
翻译中…
A pair of Wizard $i$ and Wizard $j$ (let us call this pair $(i, j)$) is said to be good when at least one of the following conditions is satisfied.
翻译中…
- Wizard
$i$has a strength of at least$b_i$and Wizard$j$has a strength of at least$b_j$. - Wizard
$i$has a strength of at least$b_j$and Wizard$j$has a strength of at least$b_i$.
翻译中…
Your objective is to make the pair $(x_i, y_i)$ good for every $i=1, \ldots, M$.
Find the minimum number of operations needed to achieve it.
翻译中…
Constraints
翻译中…
$2 \leq N \leq 100$$1 \leq a_i,b_i \leq 100$$1 \leq M \leq \frac{N(N-1)}{2}$$1 \leq x_i \lt y_i \leq N$$(x_i,y_i) \neq (x_j,y_j)$, if$i\neq j$.- All values in input are integers.
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
N
a_1 b_1
\vdots
a_N b_N
M
x_1 y_1
\vdots
x_M y_M
翻译中…
Output
翻译中…
Print the answer.
翻译中…
样例
Input #1
5
1 5
2 4
3 3
4 2
5 1
3
1 4
2 5
3 5
Output #1
2
You can perform the operation once for Wizard $1$ and once for Wizard $4$ to achieve the objective with the fewest operations.
Input #2
4
1 1
1 1
1 1
1 1
3
1 2
2 3
3 4
Output #2
0
No operation is needed.
Input #3
9
1 1
2 4
5 5
7 10
9 3
9 13
10 9
3 9
2 9
7
1 5
2 5
1 6
2 4
3 4
4 9
8 9
Output #3
22
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。