Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum Obtained of Any Permutation

Try to solve the Maximum Sum Obtained of Any Permutation problem.

Statement

You are given an array of integers nums and an array requests where requests[i] =[starti,endi]= [\text{start}_i, \text{end}_i].

The ithi^{\text{th}} request calculates the sum of all elements from index starti\text{start}_i to index endi\text{end}_i, inclusive, in nums.

Return the maximum possible total sum of all requests obtained by permuting nums in any order. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • n ==== nums.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤105\leq 10^5

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

  • requests[i].length ==2== 2

  • 0≤starti≤endi<0 \leq \text{start}_i \leq \text{end}_i < n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum Obtained of Any Permutation

Try to solve the Maximum Sum Obtained of Any Permutation problem.

Statement

You are given an array of integers nums and an array requests where requests[i] =[starti,endi]= [\text{start}_i, \text{end}_i].

The ithi^{\text{th}} request calculates the sum of all elements from index starti\text{start}_i to index endi\text{end}_i, inclusive, in nums.

Return the maximum possible total sum of all requests obtained by permuting nums in any order. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • n ==== nums.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤105\leq 10^5

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

  • requests[i].length ==2== 2

  • 0≤starti≤endi<0 \leq \text{start}_i \leq \text{end}_i < n