You are given an algebraic expression of the form (x1 + x2 + x3 + . . . + xn) ∗ (y1 + y2 + . . . + ym) and (n + m) integers. You have to find the maximum and minimum value of the expression using the given integers. For example if you are given (x1 + x2) ∗ (y1 + y2) and you are given 1, 2, 3 and 4. Then maximum value is (1 + 4) ∗ (2 + 3) = 25 where as minimum value is (4 + 3) ∗ (2 + 1) = 21.
Each input set starts with two positive integers N , M (< 51). Next line follows (N + M ) integers which are in the range of −50 to 50. Input is terminated by end of file. There will be atmost 110 testcases.
Output is one line for each case, maximum value followed by minimum value.
範例輸入 1
2 2 1 2 3 4 3 1 1 2 3 4 2 2 2 2 2 2
範例輸出 1
25 21 24 9 16 16
Pro 專屬功能: 查看這題在歷屆 CPE 出現過幾次 — 升級以解鎖.