**Subject Computer Science Java Programming**

## Question

different rows, find the maximum possible amount that the concert event will gain with the help of the ticket sales.

Input:

The first line consists of M and N. M denotes the number of seating rows in the stadium

and N denotes the number of Coldplay fans waiting in the line to get a ticket for the match. Next line consists of M space separated integers X[1], X[2], X[3]...., X[M] where X[i] denotes the number of empty seats initially in the th row.

Output:

Print in a single line the maximum dollars the concert event will gain.

Constraints:

1 <- M <= 1000

1 <- N <- 1000

1 <- X[i] <= 1000

Sum of X[i] for all 1 <= <= M will always be greater than N.

Sample Input:

34

124

Sample Output:

11

Explanation

In the sample test case, number of rows is 3 and 4 people waiting in line to get a ticket Since the maximum cost of ticket initially is 4 dollars, therefore the first person in line will buy a ticket for the 3rd row. The next person standing in line will again choose the 3rd row as it has the maximum number of seats, which will cost him 3 dollars. The next person will have 2 choices, he can either choose the 2nd row or the 3rd row which will cost him 2 dollars Similarly, the last person will choose the row will 2 seats remaining, which will cost him 2 dollars. Total cost - 4+3+2+2 - 11 dollars

## Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

*/

public class SeatingProblem {

// Main method for program execution

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

// Get two lines of input

System.out.println("Enter two lines of input:");

String input = s.nextLine();

int M = Integer.parseInt(input.split(" ")[0]);

int N = Integer.parseInt(input.split(" ")[1...

This is only a preview of the solution. Please use the purchase button to see the entire solution