AmazonOA #211
Maximize Total Area of Rectangles (SDE 2)
Estimated MediumJudge-ready
Topics (AI-labelled)GreedyIn-place Arrays
Each stick may go unused or be used in at most one rectangle, and each stick's length can be reduced by at most 1 but never increased. Each rectangle must use four sticks forming two pairs of equal sides; a square is also valid. First maximize the total area of all rectangles, then take it modulo 1000000007.
Input
The first line contains n; the second line contains the stick lengths. 1≤n≤100000, 2≤length≤10000.
Output
Output a single integer, the answer.
Example 1
Input:
6
2 6 2 6 3 5
Output:
12
Example 2
Input:
8
2 3 3 4 6 8 8 6
Output:
54
Example 3
Input:
5
3 4 5 5 6
Output:
20
Example notes
The answers are 12, 54 and 20. In the third example 6 and 5 pair up as 5, and the other 5 and 4 pair up as 4, for area 20.
Editorial
Loading solution…