Tap here to switch tabs
Problem
Submissions

Problem: Maximum Total Beauty of the Gardens

Try to solve the Maximum Total Beauty of the Gardens problem.

Statement

Alice has a collection of gardens represented by an integer array flowers, where flowers[i] denotes the number of flowers currently planted in the ithi^{th} garden. She is given an additional newFlowers flowers that she can plant across any of the gardens. She can plant any number of additional flowers in each garden, provided the total number of newly planted flowers does not exceed newFlowers.

A garden is defined as complete if it contains at least target flowers. Otherwise, it is considered incomplete.

The total beauty of the gardens is calculated as the sum of:

  • The number of complete gardens multiplied by full

  • The minimum number of flowers among all incomplete gardens multiplied by partial

If there are no incomplete gardens, the second term contributes 00 to the total beauty.

Return the maximum possible total beauty Alice can achieve.

Constraints:

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

  • 1≤1 \leq flowers[i], target ≤105\leq 10^5

  • 1≤1 \leq newFlowers ≤1010\leq 10^{10}

  • 1≤1 \leq full, partial ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Total Beauty of the Gardens

Try to solve the Maximum Total Beauty of the Gardens problem.

Statement

Alice has a collection of gardens represented by an integer array flowers, where flowers[i] denotes the number of flowers currently planted in the ithi^{th} garden. She is given an additional newFlowers flowers that she can plant across any of the gardens. She can plant any number of additional flowers in each garden, provided the total number of newly planted flowers does not exceed newFlowers.

A garden is defined as complete if it contains at least target flowers. Otherwise, it is considered incomplete.

The total beauty of the gardens is calculated as the sum of:

  • The number of complete gardens multiplied by full

  • The minimum number of flowers among all incomplete gardens multiplied by partial

If there are no incomplete gardens, the second term contributes 00 to the total beauty.

Return the maximum possible total beauty Alice can achieve.

Constraints:

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

  • 1≤1 \leq flowers[i], target ≤105\leq 10^5

  • 1≤1 \leq newFlowers ≤1010\leq 10^{10}

  • 1≤1 \leq full, partial ≤105\leq 10^5