Tap here to switch tabs
Problem
Submissions

Problem: Maximize Happiness of Selected Children

Try to solve the Maximize Happiness of Selected Children problem.

Statement

You are given an integer array happiness of length n and a positive integer k.

There are n children standing in a line, where the happiness value of the iextthi^{ ext{th}} child is given by happiness[i]. You want to select k children in k turns, choosing exactly 11 child in each turn.

In each turn, once you pick a child, the happiness value of all the remaining unselected children decreases by 11. A child’s happiness value cannot decrease below 00.

Return the maximum possible sum of the happiness values of the kk children you can select.

Constraints:

  • 1≤n==1 \leq n == happiness.length ≤2imes105\leq 2 imes 10^5

  • 1≤1 \leq happiness[i] ≤108\leq 10^8

  • 1≤k≤n1 \leq k \leq n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximize Happiness of Selected Children

Try to solve the Maximize Happiness of Selected Children problem.

Statement

You are given an integer array happiness of length n and a positive integer k.

There are n children standing in a line, where the happiness value of the iextthi^{ ext{th}} child is given by happiness[i]. You want to select k children in k turns, choosing exactly 11 child in each turn.

In each turn, once you pick a child, the happiness value of all the remaining unselected children decreases by 11. A child’s happiness value cannot decrease below 00.

Return the maximum possible sum of the happiness values of the kk children you can select.

Constraints:

  • 1≤n==1 \leq n == happiness.length ≤2imes105\leq 2 imes 10^5

  • 1≤1 \leq happiness[i] ≤108\leq 10^8

  • 1≤k≤n1 \leq k \leq n