def check_sol(sol, m_objs, H, verbose=False):
    """
    Determine whether a solution (sol) is valid.
    
    Input
    sol         list, solution with m_objs integers
    m_objs      int, number of objectives
    H           int, granularity >= 2
    verbose     bool, flag to show messages
    
    Output
    ok          bool, if ok is False, sol is invalid
    error_pos   int, position of the first invalid value found in sol (if any)
    """
    ok = True
    error_pos = None
    for pos in range(m_objs - 2, -1, -1):
        lb = 0
        ub = H - sum(sol[:pos])
        if sol[pos] >= lb and sol[pos] <= ub:
            continue
        else:
            ok = False
            error_pos = pos
            if verbose:
                print(' * %s, pos %d' % (sol, pos))
    return ok, error_pos
