Description
Solutions
Submission
Process Execution
🔥 FULLTIME🤘 INTERN

In order to increase their computing efficiency, a cloud services platform added n new processors, where the ith processor provides them a compute of power[i]. However, not all processors can be used to execute a process. If a processor with computing power of power[i] is used, then all processors that have (power[i] + 1) or (power[i] - 1) cannot be used for execution. A processor can only be used once.

Find the maximum possible sum of computing powers of chosen processors.

Function Description

Complete the function getMaximumPower in the editor.

getMaximumPower has the following parameter:

  1. int power[n]: the computing power of the processors

Returns

long integer: the maximum possible sum of computing powers

Constraints

TO-DO

Example 1:

Input:  power = [3, 3, 3, 4, 4, 1, 8]
Output: 18
Explanation:
One optimal way to choose the processors is: - Choose the 7th (1-based) processor with computing power 8. - the 6th, power 1 - the 1st, power 3; now, all the processors with power 4 cannot be chosen. - the 2nd, power 3 - the 3rd, power 3 The sum of computing powers = 8 + 1 + 3 + 3 + 3 = 18, which is the maximum possible. So, the answer is 18.
Constraints:
  • 1 <= n <= 105
  • 1 <= power[i] <= 105
Testcase

Result
Case 1

input:

output: