Subject Computer Science Java Programming

Question

(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.

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.

* SeatingProblem solver class
*/
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

Assisting Tutor
Get College Homework Help.

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

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
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