Buggy python submission (verdict: Time Limit Exceeded):
def calc_k(p, ws):
    k = 1
    s = 0
    for w in ws:
        if s + w <= p:
            s += w
        else:
            k += 1
            s = w
    return k

def search_minimum_p_internal(lp, rp, k, ws):
    "?????????P????????????????????¢?´¢??????"
    cp = (lp + rp) // 2
    k1 = calc_k(cp, ws)
    if k1 == k:
        # ???????????¨????????????????°?????????¨???k??°????????????????????????
        return cp
    elif k1 < k:
        # ???????????¨???????????????k??°???????°?????????????????????§????????????????????????????????????
        return search_minimum_p_internal(lp, cp - 1, k, ws)
    else:
        # ???????????¨???????????????k??°????????????????????????????????????????????????????¶?????????????
        return search_minimum_p_internal(cp + 1, rp, k, ws)

def search_minimum_p(k, ws):
    """
    max(P) = max(wi) * max(n)
    ????????¨???????????????1??°?????¨????????????????????????
    min(P) = max(wi)
    ?°?????????¨??????????????????????????§????????????????????????????????????
    """
    maxp = 10000 * 100000
    minp = max(ws)
    p = search_minimum_p_internal(minp, maxp, k, ws)
    while True:
        k1 = calc_k(p - 1, ws)
        if k1 == k and p > minp:
            p -= 1
        else:
            return p

n, k = map(int, input().split())
ws = []
for i in range(n):
    ws.append(int(input()))

print(search_minimum_p(k, ws))

Fixed submission:
def calc_k(p, ws):
    k = 1
    s = 0
    for w in ws:
        if w > p:
            return None
        elif s + w <= p:
            s += w
        else:
            k += 1
            s = w
    return k

def search_minimum_p(k, ws):
    """
    ?????????P????????????????????¢?´¢??????
    max(P) = max(wi) * max(n)
    ????????¨???????????????1??°?????¨????????????????????????
    min(P) = max(wi)
    ?°?????????¨??????????????????????????§????????????????????????????????????
    """
    lp = max(ws)
    rp = 10000 * 100000

    while lp <= rp:
        cp = (lp + rp) // 2
        k1 = calc_k(cp, ws)
        if k1 <= k:
            # ???????????¨???????????????k??°??\????????????????????§??????
            k2 = calc_k(cp - 1, ws)
            if k2 == None or k2 > k:
                # cp???k??°???????????????????????????p???????°??????§??????
                return cp
            else:
                # ???????°???????p????????¨??????
                rp = cp - 1
        else:
            # ???????????¨???????????????k??°????????????????????????????????????????????????????¶?????????????
            lp = cp + 1

    return None

n, k = map(int, input().split())
ws = []
for i in range(n):
    ws.append(int(input()))

print(search_minimum_p(k, ws))

Buggy python submission (verdict: Runtime Error):
def calc_k(p, ws):
    k = 1
    s = 0
    for w in ws:
        if w > p:
            return None
        elif s + w <= p:
            s += w
        else:
            k += 1
            s = w
    return k

def search_minimum_p_internal(lp, rp, k, ws):
    "?????????P????????????????????¢?´¢??????"
    cp = (lp + rp) // 2
    k1 = calc_k(cp, ws)
    if k1 == k:
        # ???????????¨????????????????°?????????¨???k??°????????????????????????
        k2 = calc_k(cp - 1, ws)
        if k2 == None or k2 > k:
            # cp???k??°???????????????????????????p???????°??????§??????
            return cp
        else:
            # ???????°???????p????????¨??????
            return search_minimum_p_internal(lp, cp - 1, k, ws)
    elif k1 < k:
        # ???????????¨???????????????k??°???????°?????????????????????§????????????????????????????????????
        return search_minimum_p_internal(lp, cp - 1, k, ws)
    else:
        # ???????????¨???????????????k??°????????????????????????????????????????????????????¶?????????????
        return search_minimum_p_internal(cp + 1, rp, k, ws)

def search_minimum_p(k, ws):
    """
    max(P) = max(wi) * max(n)
    ????????¨???????????????1??°?????¨????????????????????????
    min(P) = max(wi)
    ?°?????????¨??????????????????????????§????????????????????????????????????
    """
    maxp = 10000 * 100000
    minp = max(ws)
    return search_minimum_p_internal(minp, maxp, k, ws)

n, k = map(int, input().split())
ws = []
for i in range(n):
    ws.append(int(input()))

print(search_minimum_p(k, ws))

Fixed submission:
def calc_k(p, ws):
    k = 1
    s = 0
    for w in ws:
        if w > p:
            return None
        elif s + w <= p:
            s += w
        else:
            k += 1
            s = w
    return k

def search_minimum_p(k, ws):
    """
    ?????????P????????????????????¢?´¢??????
    max(P) = max(wi) * max(n)
    ????????¨???????????????1??°?????¨????????????????????????
    min(P) = max(wi)
    ?°?????????¨??????????????????????????§????????????????????????????????????
    """
    lp = max(ws)
    rp = 10000 * 100000

    while lp <= rp:
        cp = (lp + rp) // 2
        k1 = calc_k(cp, ws)
        if k1 <= k:
            # ???????????¨???????????????k??°??\????????????????????§??????
            k2 = calc_k(cp - 1, ws)
            if k2 == None or k2 > k:
                # cp???k??°???????????????????????????p???????°??????§??????
                return cp
            else:
                # ???????°???????p????????¨??????
                rp = cp - 1
        else:
            # ???????????¨???????????????k??°????????????????????????????????????????????????????¶?????????????
            lp = cp + 1

    return None

n, k = map(int, input().split())
ws = []
for i in range(n):
    ws.append(int(input()))

print(search_minimum_p(k, ws))