PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000045. Tích vô hướng nhỏ nhất (Minimum Scalar Product)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tích vô hướng nhỏ nhất (Minimum Scalar Product)
Minimum Scalar Product
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Given two integer vectors and , you may independently permute the coordinates of each vector. Their scalar product is . Find the minimum possible scalar product. The PHOJ version processes one vector pair and prints only the number, without the multiple-case Case #...: prefix.
Input
- The first line contains , the dimension of each vector.
- The second line contains integers .
- The third line contains integers .
Output
Print one integer: the minimum possible scalar product after permutations.
Subtasks
- Subtask 1 (20 points): ; for all .
- Subtask 2 (30 points): ; for all .
- Subtask 3 (50 points): ; for all .
Examples
Input
3
1 3 -5
-2 4 1
Output
-25
Explanation
Sort the first vector ascending to and the second descending to . Their scalar product becomes , the minimum possible.