After getting many years of experience in the industry, you're now back to coach students of your past university in both Problem Solving and Cyber Security.
Being a master of these fields yourself, let alone your amazing teaching skills, your students turned out to be pretty good too!
There are two upcoming competitions, one in Problem Solving, the other in Cyber Security. But there's one issue, the contests dates coincide, so each student will have to compete in just one of the two.
In order to get the best total results, you have quantified a numerical skill level for each student in both topics, and you want to distribute your students into two equally sized groups, such that the summation of skills of both resulting teams is the maximum possible (you'd only count the skill level of the student that corresponds to the team you placed him in).
It is surely not an issue for you to solve this problem, but how fast can you do it?
The first line of input will contain an integer $n$ $(1 \le n \le 2 \cdot 10^5)$ --- the number of students. It is guaranteed that $n$ is even (divisible by two).
The next $n$ lines will contain two integers each $p_i$ and $c_i$ $(0 \le p_i, c_i \le 10^9)$ --- the $i_{th}$ student's skill in Problem Solving and Cyber Security respectively.
Output one integer, the maximum summation of skills you can get if you distribute the $n$ students into two equally sized groups optimally.
Input | Output |
---|---|
2 4 2 5 6 Copy
|
10 Copy
|
4 5 6 7 2 0 5 4 7 Copy
|
24 Copy
|