883. Maximize Earning

0

Medium

Given an array of integers called nums, the goal is to maximize the earnings by performing the following operation any number of times:
  • Select any element nums[i] and delete it to earn nums[i] points.
  • Afterwards, delete all elements that are equal to nums[i] - 1 and nums[i] + 1.
    Find the maximum earnings that can be obtained by applying the above operation multiple times.
  • Input Format

    The first line of the input should contain an integer n, which represents the size of the nums array. The next n lines should contain integers representing the elements of the nums array.

    Output Format

    Return the maximum earnings.

    Example

    Input

    3 3 4 2

    Output

    6

    Constraints

  • 1 <= n <= 2 * 10^4
  • 1 <= nums[i] <= 10^4
  • Loading...

    View Submissions

    Console