BackmediumUncategorized uncategorized medium

Max Priority Allocation Solution

Problem Statement

You are given two arrays, `priorities` and `capacities`, where `priorities` represents the priority levels of resources and `capacities` represents the capacities of storage units. Your task is to allocate the resources to the storage units to maximize the overall priority level of the allocated resources. Return the maximum achievable priority level.

Example 1
Input
{"priorities":[11,17,23,29],"capacities":[10,20,30,40]}
Output
69

Explanation: Allocate resources with priorities 29, 23, 17, and 11 to storage units with capacities 40, 30, 20, and 10 respectively, to achieve a total priority level of 29 + 23 + 17 = 69.

Constraints

  • 1 <= priorities.length <= 10^5
  • 1 <= capacities.length <= 10^5
  • 1 <= priorities[i] <= 10^6
  • 1 <= capacities[i] <= 10^6
  • The sum of all capacities is greater than or equal to the sum of all priorities
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free