Thursday, February 12, 2026

Excursion - Calculate the number of rooms you need to book in the hotel (Super Easy)

Index of "Algorithms: Design and Analysis"
<<< Previous    Next >>>
Solve on HackerEarth
Problem
A group of students wants to visit a tour in some city 
. In total, the group has 
 boys and 
 girls. To do this, they need to stay in a hotel.

Calculate the number of rooms you need to book in the hotel, if each hotel room has 
 seats, provided that the boys can not live with the girls in the same room.

Input format

The first line specifies a number 
 denoting the number of test cases.
In each line of the test case, there are three numbers, 
.
Output format

For each test case, print one number denoting the number of rooms to be booked at the hotel.

Constraints





Sample Input
4
13 7 2
5 5 3
2 2 2
5 4 5
Sample Output
11
4
2
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
For test 13 7 2 answer is 11, because need for boys 7 rooms and for girls need 4 rooms.

For test 5 5 3 answer is 4, because need for boys 2 rooms and for girls need 2 rooms.




Code

import math

def solve(N, M, K):
    out = math.ceil(N / K) + math.ceil(M / K)
    return out

T = int(input())
for _ in range(T):
    N, M, K = map(int, input().split())
    out = solve(N, M, K)
    print(out)

No comments:

Post a Comment