Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5594 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3412 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 783 |

@Manikanta punnam | 605 |

@sriramgoparaju99 | 598 |

@rdakka | 538 |

@praveenbgp6 | 529 |

@prankursharma31 | 518 |

@yashkaril4 | 517 |

@purohitmn02 | 467 |

@sonamnigam1999 | 443 |

@sonamkumari63928 | 441 |

@shubhamstudent5 | 433 |

Complete Leaderboard |

Ishaan is given N integers in the form of an array A. He is asked to select all of these integers in any order. For selecting every integer he gets some points. He needs to maximize those points.

For every integer he selects, he gets points equal to the value of :

**the selected integer * number of integers selected before the current integer** (Refer example for explanation)

Help him find the maximum points he can get provided **he can select every integer exactly 1 time**.

**Example 1:**

**â€‹Input :** arr[ ] = {1, 2, 2, 4, 9}
**Output :**
**Explanation:**
First he selects 1
Points : 1 * 0 (no integer selected before
this), Total Points = 0
Then he selects 2
Points : 2 * 1 (1 selected before this)
Total Points = 2
Then he selects 2
Points : 2 * 2 (1,2 selected before this)
Total Points = 6
Then he selects 4
Points : 4 * 3 (1,2,2 selected before this)
Total Points = 18
Then he selects 9
Points : 9 * 4 (1,2,2,4 selected before this)
Total Points = **54**

**â€‹Example 2:**

**Input :** arr[ ] = {2, 2, 2, 2} **
Output :** 12

**Your Task:**

This is a function problem. The input is already taken care of by the driver code. You only need to complete the function **selection()** that takes an array **(arr)**, sizeOfArray **(n)**, and return the maximum points he can get provided. The driver code takes care of the printing.

**Expected Time Complexity:** O(N*LOG(N)).

**Expected Auxiliary Space:** O(1).

**Constraints :**

1 ≤ N ≤ 10^{5}

1 ≤ A[i] ≤ 10^{5}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
The Optimal Selection

...