Monk and Multiplication
Practice
3.8 (114 votes)
Approved
Easy
Open
Priority queue
Trees
Problem
68% Success 23317 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

The Monk learned about priority queues recently and asked his teacher for an interesting problem. So his teacher came up with a simple problem. He now has an integer array A. For each index i, he wants to find the product of the largest, second largest and the third largest integer in the range [1,i].
Note: Two numbers can be the same value-wise but they should be distinct index-wise.

Input:
The first line contains an integer N, denoting the number of elements in the array A.
The next line contains N space separated integers, each denoting the ith integer of the array A.

Output:
Print the answer for each index in each line. If there is no second largest or third largest number in the array A upto that index, then print "-1", without the quotes.

Constraints:
1 <= N <= 100000
0 <= A[i] <= 1000000

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
95 votes
Tags:
ApprovedEasyHeapsOpenPriority Queue
Points:20
29 votes
Tags:
ApprovedData StructuresEasyMapsOpenPriority QueuePriority queueTrees
Points:20
25 votes
Tags:
Data StructuresEasyHash MapsHash TablesHeapsPriority queueTrees