100 atcoder#ABC194B. [ABC194B] Job Assignment

[ABC194B] Job Assignment

Score : 200200 points

Problem Statement

Your company has NN employees, called Employee 11 through NN. You have received two work orders, called Work A and B, which must be completed. Employee ii can complete Work A in AiA_i minutes and Work B in BiB_i minutes.

You will assign each work to one employee. You can assign both works to the same employee, in which case the time it takes for him/her to complete them is the sum of the times it takes for him/her to do them individually. If you assign the works to different employees, the time it takes for them to complete them is the longer of the times it takes for them to do their respective works. Find the shortest possible time needed to complete the works.

Constraints

  • 2N10002 \le N \le 1000
  • 1Ai1051 \le A_i \le 10^5
  • 1Bi1051 \le B_i \le 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 B1B_1

A2A_2 B2B_2

A3A_3 B3B_3

\hspace{15pt} \vdots

ANA_N BNB_N

Output

Print the shortest possible time needed to complete the works, in minutes.

3
8 5
4 4
7 9
5

If you assign Work A to Employee 22 and Work B to Employee 11, they will complete them in 44 and 55 minutes, respectively. Since you assigned the works to different employees, it will take max(4,5)=5\max(4, 5) = 5 minutes for the two works to be finished. It is impossible to finish them earlier.

3
11 7
3 2
6 7
5

It is optimal to assign both works to Employee 22. Note that if you assign both works to the same employee, the time it takes for him/her to complete them is the sum of the times it takes for him/her to do them individually.