atcoder#ARC142E. [ARC142E] Pairing Wizards
[ARC142E] Pairing Wizards
Score : points
Problem Statement
There are wizards, numbered . Wizard has a strength of and plans to defeat a monster with a strength of .
You can perform the following operation any number of times.
- Increase the strength of any wizard of your choice by .
A pair of Wizard and Wizard (let us call this pair ) is said to be good when at least one of the following conditions is satisfied.
- Wizard has a strength of at least and Wizard has a strength of at least .
- Wizard has a strength of at least and Wizard has a strength of at least .
Your objective is to make the pair good for every . Find the minimum number of operations needed to achieve it.
Constraints
- , if .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
5
1 5
2 4
3 3
4 2
5 1
3
1 4
2 5
3 5
2
You can perform the operation once for Wizard and once for Wizard to achieve the objective with the fewest operations.
4
1 1
1 1
1 1
1 1
3
1 2
2 3
3 4
0
No operation is needed.
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
22