/**
 * Given a list of tunnel lengths and a maximum length, create a tuple containing lengths until it exceeds
 * the maximum length and then break out of the loop.
 *
 * @param tunnelLengths List of integers representing the lengths of tunnels.
 * @param maxLength Maximum allowed length.
 * @return Tuple containing the lengths of tunnels until the maximum length is reached.
 */
fun createTunnelLength(tunnelLengths: List<Int>, maxLength: Int): List<Int> {

    var totalLength = 0
    val tunnelList = mutableListOf<Int>()

    for (length in tunnelLengths) {
        if (totalLength + length <= maxLength) {
            totalLength += length
            tunnelList.add(length)
        } else {
            break
        }
    }

    return tunnelList
}
/**
 * Given a list of tunnel lengths and a maximum length, create a tuple containing lengths until it exceeds
 * the maximum length and then break out of the loop.
 *
 * @param tunnelLengths List of integers representing the lengths of tunnels.
 * @param maxLength Maximum allowed length.
 * @return Tuple containing the lengths of tunnels until the maximum length is reached.
 */
fun createTunnelLength(tunnelLengths: List<Int>, maxLength: Int): List<Int> {
/**
 * Given a list of tunnel lengths and a maximum length, create a tuple containing lengths until it exceeds
 * the maximum length and then break out of the loop.
 *
 * @param tunnelLengths List of integers representing the lengths of tunnels.
 * @param maxLength Maximum allowed length.
 * @return Tuple containing the lengths of tunnels until the maximum length is reached.
 */
fun createTunnelLength(tunnelLengths: List<Int>, maxLength: Int): List<Int> {

    var totalLength = 0
    val tunnelList = mutableListOf<Int>()

    for (length in tunnelLengths) {
        if (totalLength + length <= maxLength) {
            totalLength += length
            tunnelList.add(length)
        } else {
            break
        }
    }

    return tunnelList
}