Pricing Dilemma


Submit solution


Points: 3 (partial)
Time limit: 1.0s
Python 3.0s
Memory limit: 256M

Author:
Problem type

In the bustling market of Robsville, merchants often engage in competitive pricing strategies. One such strategy involves comparing the product value of two pairs of dictinct items. The product difference between two pairs of items (a, b) and (c, d) is defined as (a × b) - (c × d). This difference helps merchants evaluate the relative value of their inventory combinations.

As a merchant, you are given a list of integers of size \(N\), where each element \(a_i\) represents the value of an item in your inventory. You task is to select four dictinct items (indices w, x, y, z) such that the product difference between the pairs (nums[w], nums[x]) and (nums[y], nums[z]) is maximized.

Constraints

\(4 \le N \le 10^{4}\)

\(1 \le a_i \le 10^{4}\)

Input Specification

The first line of input will contain \(N\). The next line will contain \(N\) spaced-separated integers \(a_i\).

Output Specification

Output the maximized difference.

Sample Input 1

5
5 6 2 7 4

Sample Output 1

34

Explanation for Sample 1

By selecting pairs (6, 7) and (2, 4), the product difference is (6 × 7) – (2 × 4) = 42 – 8 = 34.

Sample Input 2

7
4 2 5 9 7 4 8

Sample Output 2

64

Explanation for Sample 2

By selecting pairs (8, 9) and (2, 4), the product difference is (8 × 9) – (2 × 4) = 72 – 8 = 64.


Comments

There are no comments at the moment.