FastPrepFastPrep
Problem Brief

Maximize Total Memory Points

INTERNOA

FastPrep.io Academy has recently introduced an exciting new course focused on Quantum Physics, providing learners with an opportunity to explore the fascinating world of quantum mechanics and its applications.πŸ™‚β€β†”οΈ

However, the course follows a specific requirement: before studying the i-th chapter, the student must revisit all the previous chapters. This means that when reading the i-th chapter, the student accumulates a total of:

Students have the flexibility to read the chapters in any order and aim to maximize their total memory points. The goal is to determine the maximum possible total memory points a student can accumulate while ensuring that all chapters are read at least once.

Your task is to find and return the highest possible total memory points that a student can achieve by choosing the optimal reading order.

The highest possible total memory points that can be accumulated throughout the course is 26.

1Example 1

Input
memory = [3, 4, 5]
Output
26
Explanation
Considering all permutations of reading the chapters and their total memory points: β€’ [3, 4, 5] β†’ Corresponding memory points will be [3, 7, 12], thus total memory points will be 3 + 7 + 12 = 21 β€’ [3, 5, 4] β†’ Corresponding memory points will be [3, 8, 12], thus total memory points will be 3 + 8 + 12 = 23 β€’ [4, 3, 5] β†’ Corresponding memory points will be [4, 7, 12], thus total memory points will be 4 + 7 + 12 = 23 β€’ [4, 5, 3] β†’ Corresponding memory points will be [4, 9, 12], thus total memory points will be 4 + 9 + 12 = 25 β€’ [5, 3, 4] β†’ Corresponding memory points will be [5, 8, 12], thus total memory points will be 5 + 8 + 12 = 25 β€’ [5, 4, 3] β†’ Corresponding memory points will be [5, 9, 12], thus total memory points will be 5 + 9 + 12 = 26

Constraints

Limits and guarantees your solution can rely on.

  • 1 ≀ n ≀ 10^5
  • -10^3 ≀ memory[i] ≀ 10^3
public long maximizeCumulativeMemoryPoints(int[] memory) {
  // write your code here
}
Input

memory

[3, 4, 5]

Output

26

Sign in to submit your solution.