#QHD0000076. Tối ưu tích của hai tổng (Expression Again)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tối ưu tích của hai tổng (Expression Again)
Expression Again
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Consider the expression
You are given exactly integers, which may be negative, zero, or positive. Assign each occurrence to exactly one position: choose exactly numbers for the -sum and put the remaining exactly numbers in the -sum. Equal-valued occurrences are distinct and may be assigned separately.
For every permitted assignment, multiply the two group sums. Determine both the maximum and minimum product. The order within a group is irrelevant, but group sizes must be exact. Either group sum, and hence the product, may be negative.
Input
The first line contains positive integers . The second line contains integers, each in .
Output
Print the maximum product first, then the minimum product, separated by one space.
Subtasks
-
Subtask 1 (20 points): ; ; ; exactly numbers in the first group.
-
Subtask 2 (30 points): ; ; ; exactly numbers in the first group.
-
Subtask 3 (50 points): ; ; ; exactly numbers in the first group.
Examples
Example 1
Input
2 2
1 2 3 4
Output
25 21
Explanation
The total is . Choosing gives sums and , product (maximum). Choosing gives sums and , product (minimum).
Example 2
Input
3 1
1 2 3 4
Output
24 9
Explanation
Choosing yields ; choosing yields .
Example 3
Input
2 2
2 2 2 2
Output
16 16
Explanation
Every assignment yields sums and , so both the maximum and minimum equal .