4 条题解

  • 0
    @ 2024-5-25 12:19:20
    def get_wood_amount(trees, cut_height):
        # 计算砍下的木材总长度
        wood = sum(tree - cut_height for tree in trees if tree > cut_height)
        return wood
    
    def find_max_height(trees, m):
        low, high = 0, max(trees)
        result = 0
    
        while low <= high:
            mid = (low + high) // 2
            wood = get_wood_amount(trees, mid)
    
            if wood >= m:
                result = mid
                low = mid + 1
            else:
                high = mid - 1
    
        return result
    
    # 读取输入
    n, m = map(int, input().split())
    trees = list(map(int, input().split()))
    
    # 计算结果
    max_cut_height = find_max_height(trees, m)
    
    # 输出结果
    print(max_cut_height)
    
    

    信息

    ID
    89
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    递交数
    914
    已通过
    203
    上传者