| 2026 Spring UT CS104c Final Exam |
|---|
| Закончено |
Magikarp is on an anti-diet and wants to maximize the amount of calories that he eats today. He currently has a selection of $$$n$$$ restaurants. The $$$i$$$th restaurant serves only 2 dishes: an appetizer with $$$a_i$$$ calories and an entree with $$$b_i$$$ calories. Magikarp will choose exactly 1 restaurant for an appetizer and exactly 1 for an entree, while maximizing the total number of calories he consumes. However, he does not want to order his 2 dishes from the same restaurant. What is the maximum sum of calories Magikarp can order?
The first line of input contains $$$n$$$ $$$(2\le n\le 2\cdot 10^5)$$$ — the total number of restaurants.
The $$$i$$$th of the next $$$n$$$ lines contains 2 integers $$$a_i$$$ and $$$b_i$$$ $$$(0\le a_i, b_i\le 10^6)$$$ — the number of calories in the appetizer and entree, respectively, at restaurant $$$i$$$.
Output a single number, the maximum sum of calories Magikarp can order.
56 12 710 43 31 4
17
2100 1001 2
102
For the first sample, Magikarp can order an appetizer from restaurant $$$3$$$ and an entree from restaurant $$$2$$$ for a calorie total of $$$10 + 7 = 17$$$. It can be shown that no other combination produces a larger total.
For the second sample, Magikarp would want to order both the appetizer and entree from restaurant $$$1$$$, but this is not allowed. The best that he can do is order the appetizer from restaurant $$$1$$$ and the entree from restaurant $$$2$$$ for a calorie total of $$$100+2=102$$$.
| Название |
|---|


