| UFPE Starters Final Try-Outs 2026 |
|---|
| Finished |
Drex needed a break from implementing data structures, so he decided to relax with a few rounds of Balatro. He's on a big run. To win the game, he must defeat a powerful boss that can fight back and deal damage to him. Both Drex and the boss have hands consisting of $$$n$$$ integers. Drex is allowed to rearrange the order of the integers in his hand before the fight begins.
The total damage Drex takes is calculated as: $$$\sum_{i=1}^{n} |d_i - b_i|$$$, where $$$d_i$$$ represents the $$$i$$$-th integer in Drex's hand (after rearranging) and $$$b_i$$$ represents the $$$i$$$-th integer in the boss's hand.
Drex wants to rearrange his hand in a way that minimizes the total damage he receives.
The first line contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$).
The second line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$-10^9 \le d_i \le 10^9$$$), Drex's hand.
The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$), the boss's hand.
Print a single integer, the minimum total damage Drex will take from the boss.
31 2 33 1 2
0
If Drex rearranges his hand to $$$[3,1,2]$$$, he will take $$$|3-3| + |1-1| + |2-2| = 0$$$ damage.
| Name |
|---|


