Tap here to switch tabs
Problem
Submissions

Problem: Maximize the Total Height of Unique Towers

Try to solve the Maximize the Total Height of Unique Towers problem.

Statement

You are given an array of positive integers maximumHeight, where maximumHeight[i] represents the maximum allowable height for the ii-th tower.

You need to assign a positive integer height to each tower such that:

  • The height assigned to the ii-th tower is less than or equal to maximumHeight[i].

  • All tower heights are unique.

Return the maximum possible total sum of heights across all towers. If it is impossible to assign valid heights to every tower, return −1-1.

Constraints:

  • 1≤1 \leq maximumHeight.length ≤105\leq 10^5

  • 1≤1 \leq maximumHeight[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximize the Total Height of Unique Towers

Try to solve the Maximize the Total Height of Unique Towers problem.

Statement

You are given an array of positive integers maximumHeight, where maximumHeight[i] represents the maximum allowable height for the ii-th tower.

You need to assign a positive integer height to each tower such that:

  • The height assigned to the ii-th tower is less than or equal to maximumHeight[i].

  • All tower heights are unique.

Return the maximum possible total sum of heights across all towers. If it is impossible to assign valid heights to every tower, return −1-1.

Constraints:

  • 1≤1 \leq maximumHeight.length ≤105\leq 10^5

  • 1≤1 \leq maximumHeight[i] ≤109\leq 10^9