Room Assignment
InterviewTime limit2sMemory limit512 MB
Count students by grade and gender, then combine grades 1-2 into one pool and split grades 3-6 by gender, computing rooms as ceil(count/K).
- Level
Easy3 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
An elementary school is going on a three day field trip. Every student from grade 1 to grade 6 needs a room, and the rules are these.
- Grades 1 and 2 share a room with no separation by gender and no separation by grade.
- Grades 3 and 4 share a room with no separation by grade, but boys stay with boys and girls stay with girls.
- Grades 5 and 6 follow the same rule as grades 3 and 4.
- A room may hold a single student.
Given the largest number of students that one room holds, write a program that finds the minimum number of rooms needed to place every student under these rules.
For example, if the students on the trip are counted as below and , then 9 rooms are needed.
Input
The first line has the number of students on the trip () and the largest number of students one room holds (), separated by a space.
Each of the next lines has the gender and the grade () of one student, separated by a space. is 0 for a girl and 1 for a boy.
Output
Print the minimum number of rooms needed to place every student, on one line.