Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum Obtained of Any Permutation

med
30 min
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] =[extstarti,extendi]= [ ext{start}_i, ext{end}_i].

The iextthi^{ ext{th}} request calculates the sum of all elements from index $ ext{start}_i$ to index $ ext{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≤extstarti≤extendi<0 \leq ext{start}_i \leq ext{end}_i < n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum Obtained of Any Permutation

med
30 min
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] =[extstarti,extendi]= [ ext{start}_i, ext{end}_i].

The iextthi^{ ext{th}} request calculates the sum of all elements from index $ ext{start}_i$ to index $ ext{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≤extstarti≤extendi<0 \leq ext{start}_i \leq ext{end}_i < n