Seating arrangement

0

0 votes
Open, Open, Open, Binary search algorithm, Searching, Basic Programming, Searching algorithm, Algorithms, Easy, Binary Search, approved
Problem

There are M rows of benches in a classroom. N students come to the classroom one-by-one and take a seat. Every student contains a preferred number. The rows are numbered from 1 to N and the maximum capacity of all the rows is K. The students come to the class in a sequential manner starting from 1 to N and follow these rules for the seating arrangement:

  • Every student must sit in his or her preferred row (if the row is not full)
  • If the preferred row is fully occupied, then the student must sit in the next vacant row (next row for N will be 1)
  • If all the seats are occupied, then the student cannot sit anywhere.

Your task is to determine the total number of students who cannot sit in their preferred row.

Note: This includes the students that did not get a seat at all.

Input format

  • First line: Three integers N, M, and K that denotes the number of students, number of rows, and maximum capacity of a row respectively
  • Next line: N space-separated integers Ai that denote the preferred row of the ith student

Output format

Print the total number of students who cannot sit in their preferred row.

Constraints

1N,M105

1K500

1AiM

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Student 4 and student 5 did not get their preferred seats.

Editor Image

?