Just another normal weekday in a normal weather, you, as a student, woke up and are being ready for school. Though there is one thing that is abnormal - you wanted to start your day with a great feast.
You have $N$ food items and $N$ toppings. Each food item has a food value $a_i$ assigned to them, while the toppings have topping values $b_i$ assigned to them. When a food and a topping is combined together, they make a dish with tastiness value of $a_i \times b_i$. You want to combine each food item with a topping (without overlaps), creating $N$ dishes. Your goal is to maximise the sum of the tastiness values of all dishes made.
Input
The first line contains an integer $N$.
The second line contains $N$ integers, the food values $a_i$.
The third line contains $N$ integers, the topping values $b_i$.
Output
Output the maximum sum of the tastiness values of all dishes made.
Constraints
For all test cases: $1 \le N \le 10^6, 1 \le a_i, b_i \le 1000$.
Subtask 1 (50%): $N \le 10$
Subtask 2 (50%): No other constraints
Sample Test Cases
Input | Output | |
---|---|---|
2 8 4 3 7 |
68 | |
Pairing up $3, 4$ and $7, 8$ gives us a total dish value of $3 \times 4 + 7 \times 8 = 68$. |
Scoring: Per Subtask
Authored by s17f18
Appeared in 2025 Mini Comp 2