P18159 [GeeksforGeeks] Maximum product of increasing subsequence of size 32027
普及
题目描述

Given a sequence of non-negative integers, find the subsequence of length 3 having maximum product, with the elements of the subsequence being in increasing order.

Example 1:
​Input:
n = 8
arr[ ] = {6, 7, 8, 1, 2, 3, 9, 10}
Output:
8 9 10
Explanation: 3 increasing elements of
the given arrays are 8,9 and 10 which
forms the subsequence of size 3 with
maximum product.
​Example 2:
Input:
n = 4
arr[ ] = {3, 4, 2, 1}
Output:
Not Present

Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function maxProductSubsequence() that takes an array arr, sizeOfArray n, and return the subsequence of size 3 having the maximum product, numbers of subsequence being in increasing order. If no such sequence exists, return "-1". The driver code takes care of the printing.
Expected Time Complexity: O(N*LOG(N)).
Expected Auxiliary Space: O(N).
Constraints:
1 <= N <= 10^{5}
1 <= Arr[i] <= 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
n = 8 arr[ ] = {6, 7, 8, 1, 2, 3, 9, 10}
样例输出
8 9 10