/**
 * Given a list of shifts as tuples and a maximum number of hours, modify the shifts by reducing the hours of each shift
 * until the total hours for all shifts is less than or equal to the maximum hours. Return the modified shifts.
 *
 * @param shifts A list of shifts represented as tuples (shift_start, shift_end)
 * @param maxHours Maximum number of hours allowed for all shifts
 * @return Modified shifts with reduced hours
 *
 * Example:
 * firefighterShifts([(6, 14), (14, 22), (22, 30)], 24)
 * Output: [(6, 14), (14, 22)]
 */
fun firefighterShifts(shifts: List<Pair<Int, Int>>, maxHours: Int): List<Pair<Int, Int>> {

    var totalHours = 0
    val modifiedShifts = mutableListOf<Pair<Int, Int>>()
    for ((start, end) in shifts) {
        val hours = end - start
        if (totalHours + hours <= maxHours) {
            modifiedShifts.add(Pair(start, end))
            totalHours += hours
        } else {
            break
        }
    }
    return modifiedShifts
}
/**
 * Given a list of shifts as tuples and a maximum number of hours, modify the shifts by reducing the hours of each shift
 * until the total hours for all shifts is less than or equal to the maximum hours. Return the modified shifts.
 *
 * @param shifts A list of shifts represented as tuples (shift_start, shift_end)
 * @param maxHours Maximum number of hours allowed for all shifts
 * @return Modified shifts with reduced hours
 *
 * Example:
 * firefighterShifts([(6, 14), (14, 22), (22, 30)], 24)
 * Output: [(6, 14), (14, 22)]
 */
fun firefighterShifts(shifts: List<Pair<Int, Int>>, maxHours: Int): List<Pair<Int, Int>> {
/**
 * Given a list of shifts as tuples and a maximum number of hours, modify the shifts by reducing the hours of each shift
 * until the total hours for all shifts is less than or equal to the maximum hours. Return the modified shifts.
 *
 * @param shifts A list of shifts represented as tuples (shift_start, shift_end)
 * @param maxHours Maximum number of hours allowed for all shifts
 * @return Modified shifts with reduced hours
 *
 * Example:
 * firefighterShifts([(6, 14), (14, 22), (22, 30)], 24)
 * Output: [(6, 14), (14, 22)]
 */
fun firefighterShifts(shifts: List<Pair<Int, Int>>, maxHours: Int): List<Pair<Int, Int>> {

    var totalHours = 0
    val modifiedShifts = mutableListOf<Pair<Int, Int>>()
    for ((start, end) in shifts) {
        val hours = end - start
        if (totalHours + hours <= maxHours) {
            modifiedShifts.add(Pair(start, end))
            totalHours += hours
        } else {
            break
        }
    }
    return modifiedShifts
}