(2) Sean is a big fan of Coldplay, which is a British rock band. Coldplay is in New York City for their "A Head Full of Dreams Tour". They will perform in the MetLife Stadium. So, Sean decided to go and watch his favorite band perform. After reaching the stadium, he saw that many people have lined up for the concert tickets. He knows that there are M rows in the stadium with different seating capacities. They may or may not be equal. The price of the ticket depends on the row. If the row has K (always greater than 0) vacant seats, then the price of the ticket will be K dollars. Now, every fan standing in the line will get a ticket one by one. Given the seating capacities of
different rows, find the maximum possible amount that the concert event will gain with the help of the ticket sales.

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.

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

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:

Sample Output:

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 PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

* SeatingProblem solver class
public class SeatingProblem {
    // Main method for program execution
    public static void main(String[] args) {
       Scanner s = new Scanner(;
       // 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...

By purchasing this solution you'll be able to access the following files:
Solution.PNG and

for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats