Ensure that you are logged in and have the required permissions to access the test.

A) Happy Days

4.4

5 votes
Problem

Since exams are over, happy days have started!
Well, we should maximize our happiness to get the most out of it.

Each item has a happiness level of either 1,2,3 or 4. Items need to be picked in groups of 3, and happiness of this group of items A, B, C is defined as A*B*C, maximize and return the total happiness that you can get from the given set of items.

Input :

N - Total number of items,
An array of size N, Arr[i] denoting the value of the ith item.

Constraints :

3<=N<=105

Output :

Total maximum happiness that you can achieve.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The best way to pick group 1 is 3 4 & 3, to obtain 3*3*4= 36, remaining 2 can't be picked as items can only be picked in groups of 3

Editor Image

?