Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Allocation

????????????????????? wi(i=0,1,...n???1) ??? n ??????????????????
????????????????????¢????????????????????????????????????
????????????????????? k ??°?????????????????????????????????
???????????????????????£?¶??????? 0 ?????\??????????????????????????¨?????§???????????????
???????????????????????????????????????????????§????????? P ????¶????????????????????????????
?????§????????? P ?????????????????????????????§??±?????§??????

n???k???wi ???????????????????????§????????????????????????????????????????????????
?????§????????? P ???????°????????±???????????????°????????????????????????????????????

"""
import sys

# ??????????????\????????????
def kenzan(P, wi, n, k):
    t = 1 # ????????????
    s = 0 # ?????????
    for i in wi:
        s += i
        if s > P: # ????????????
            t += 1
            if t > k: # ??°??°????????????
                return False
            s = i
    
    if t < k: #?????????????????£???
        return False
    return True

def main():
    """ ????????? """
    n,k = list(map(int,input().split()))
    istr = sys.stdin.read()
    wi = list(map(int,istr.splitlines()))

    # ?????§?????¨?????????????±???????
    P = 0
    total = 0
    for w in wi:
        if P < w:
            P = w
        total += w
    na = int(total / n) # ?????????????????????
    if total % n > 0:
        na += 1
    ka = int(total / k) # ???????????????????????????
    if total % k > 0:
        ka += 1
    # ?????? P (??????????????§??????????????????????????????????±?????????????
    if P < na:
        P = na
    if P < ka:
        P = ka

    ret = False
    while ret == False:
        if kenzan(P, wi, n, k) == True:
            break
        else:
            P += 1

    print(P)


if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Allocation

????????????????????? wi(i=0,1,...n???1) ??? n ??????????????????
????????????????????¢????????????????????????????????????
????????????????????? k ??°?????????????????????????????????
???????????????????????£?¶??????? 0 ?????\??????????????????????????¨?????§???????????????
???????????????????????????????????????????????§????????? P ????¶????????????????????????????
?????§????????? P ?????????????????????????????§??±?????§??????

n???k???wi ???????????????????????§????????????????????????????????????????????????
?????§????????? P ???????°????????±???????????????°????????????????????????????????????

"""
import sys

# ??????????????\????????????
def kenzan(P, w, n, k):
#    print("P:{} kosu:{} track:{}".format(P,n,k))
    t = 1 # ????????????
    s = 0 # ?????????
    st = 0
    for i in range(n):
        x = s + w[i]
#        print("max:{} nimotu[{}]:{} + sekisai:{} = {} track:{}".format(P,i,w[i],s,x,t))
        if x > P: # ????????????
            t += 1
            st += s
            s = w[i]
#            print("next track:{} sekisai:{}".format(t,s))
            if t > k: # ??°??°????????????
#                print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st))
                return st
        else:
            s = x

#    print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st))
    return 0

def main():
    """ ????????? """
    n,k = list(map(int,input().split()))
    istr = sys.stdin.read()
    wi = list(map(int,istr.splitlines()))

    # ?????§?????¨???????????¨????°????????±???????
    P = 0
    total = 0
    min = 100000
    for w in wi:
        if P < w:
            P = w
        if min > w:
            min = w
        total += w
    na = int(total / n) # ?????????????????????
    if total % n > 0:
        na += 1
    ka = int(total / k) # ???????????????????????????
    if total % k > 0:
        ka += 1
    # ?????? P (??????????????§??????????????????????????????????±?????????????
#    print("kosu:{} MAX:{} MIN:{} na:{} ka:{} total:{}".format(n, P, min, na, ka, total))
    if P < na:
        P = na
    if P < ka:
        P = ka
    z = 0
    while P <= total:
        st = kenzan(P, wi, n, k)
#        print("??????????????°:{} ??????????????°??°:{} ?????????????????§??????:{} ????????????????????????:{} ??????????????????:{} ??????:{}".format(n, k, P, total, st,z))
        if st == 0:
            a = P - z
            b = P
            break
        z = int((total-st)/k)
        if z < 1:
            z = 1
        P += z
    
    while b - a > 0:
        x = int((b - a) / 2)
        if x < 1:
            a = b
        P = x + a
        st = kenzan(P, wi, n, k)
#        print("P:{} MAX:{} MIN:{} sekisai:{}".format(P, b, a, st))
        if st == 0:
            b = P
        else:
            a = P

    print(P)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Allocation

????????????????????? wi(i=0,1,...n???1) ??? n ??????????????????
????????????????????¢????????????????????????????????????
????????????????????? k ??°?????????????????????????????????
???????????????????????£?¶??????? 0 ?????\??????????????????????????¨?????§???????????????
???????????????????????????????????????????????§????????? P ????¶????????????????????????????
?????§????????? P ?????????????????????????????§??±?????§??????

n???k???wi ???????????????????????§????????????????????????????????????????????????
?????§????????? P ???????°????????±???????????????°????????????????????????????????????

"""
import sys

# ??????????????\????????????
def kenzan(P, w, n, k):
#    print("P:{} kosu:{} track:{}".format(P,n,k))
    t = 1 # ????????????
    s = 0 # ?????????
    for i in range(n):
        x = s + w[i]
#        print("max:{} nimotu[{}]:{} + sekisai:{} = {} track:{}".format(P,i,w[i],s,x,t))
        if x > P: # ????????????
            t += 1
            s = w[i]
#            print("next track:{} sekisai:{}".format(t,s))
            if t > k: # ??°??°????????????
#                print("\tfalse track:{}/{} s:{}".format(t,k,s))
                return False
        else:
            s = x

#    if t < k: #?????????????????£???
#        print("\tfalse track:{}/{}".format(t,k))
#        return False
    return True

def main():
    """ ????????? """
    n,k = list(map(int,input().split()))
    istr = sys.stdin.read()
    wi = list(map(int,istr.splitlines()))

    # ?????§?????¨?????????????±???????
    P = 0
    total = 0
    for w in wi:
        if P < w:
            P = w
        total += w
    na = int(total / n) # ?????????????????????
    if total % n > 0:
        na += 1
    ka = int(total / k) # ???????????????????????????
    if total % k > 0:
        ka += 1
    # ?????? P (??????????????§??????????????????????????????????±?????????????
#    print("MAX:{} na:{} ka:{}".format(P,na,ka))
    if P < na:
        P = na
    if P < ka:
        P = ka

    ret = False
    while ret == False:
        if kenzan(P, wi, n, k) == True:
            break
        else:
            P += 1
        if P > total:
#            print("OVER ERROR P:{} total:{}  na:{} ka:{}".format(P,total, na, ka))
            break
    print(P)


if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Allocation

????????????????????? wi(i=0,1,...n???1) ??? n ??????????????????
????????????????????¢????????????????????????????????????
????????????????????? k ??°?????????????????????????????????
???????????????????????£?¶??????? 0 ?????\??????????????????????????¨?????§???????????????
???????????????????????????????????????????????§????????? P ????¶????????????????????????????
?????§????????? P ?????????????????????????????§??±?????§??????

n???k???wi ???????????????????????§????????????????????????????????????????????????
?????§????????? P ???????°????????±???????????????°????????????????????????????????????

"""
import sys

# ??????????????\????????????
def kenzan(P, w, n, k):
#    print("P:{} kosu:{} track:{}".format(P,n,k))
    t = 1 # ????????????
    s = 0 # ?????????
    st = 0
    for i in range(n):
        x = s + w[i]
#        print("max:{} nimotu[{}]:{} + sekisai:{} = {} track:{}".format(P,i,w[i],s,x,t))
        if x > P: # ????????????
            t += 1
            st += s
            s = w[i]
#            print("next track:{} sekisai:{}".format(t,s))
            if t > k: # ??°??°????????????
#                print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st))
                return st
        else:
            s = x

#    print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st))
    return 0

def main():
    """ ????????? """
    n,k = list(map(int,input().split()))
    istr = sys.stdin.read()
    wi = list(map(int,istr.splitlines()))

    # ?????§?????¨???????????¨????°????????±???????
    P = 0
    total = 0
    min = 100000
    for w in wi:
        if P < w:
            P = w
        if min > w:
            min = w
        total += w
    na = int(total / n) # ?????????????????????
    if total % n > 0:
        na += 1
    ka = int(total / k) # ???????????????????????????
    if total % k > 0:
        ka += 1
    # ?????? P (??????????????§??????????????????????????????????±?????????????
#    print("kosu:{} MAX:{} MIN:{} na:{} ka:{} total:{}".format(n, P, min, na, ka, total))
    if P < na:
        P = na
    if P < ka:
        P = ka
    z = 0
    while P <= total:
        st = kenzan(P, wi, n, k)
#        print("??????????????°:{} ??????????????°??°:{} ?????????????????§??????:{} ????????????????????????:{} ??????????????????:{} ??????:{}".format(n, k, P, total, st,z))
        if st == 0:
            a = P - z
            b = P
            break
        z = int((total-st)/k)
        if z < 1:
            z = 1
        P += z
    
    while b - a > 0:
        x = int((b - a) / 2)
        if x < 1:
            a = b
        P = x + a
        st = kenzan(P, wi, n, k)
#        print("P:{} MAX:{} MIN:{} sekisai:{}".format(P, b, a, st))
        if st == 0:
            b = P
        else:
            a = P

    print(P)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Allocation

????????????????????? wi(i=0,1,...n???1) ??? n ??????????????????
????????????????????¢????????????????????????????????????
????????????????????? k ??°?????????????????????????????????
???????????????????????£?¶??????? 0 ?????\??????????????????????????¨?????§???????????????
???????????????????????????????????????????????§????????? P ????¶????????????????????????????
?????§????????? P ?????????????????????????????§??±?????§??????

n???k???wi ???????????????????????§????????????????????????????????????????????????
?????§????????? P ???????°????????±???????????????°????????????????????????????????????

"""
import sys

# ??????????????\????????????
def kenzan(P, w, n, k):
#    print("P:{} kosu:{} track:{}".format(P,n,k))
    t = 1 # ????????????
    s = 0 # ?????????
    st = 0
    for i in range(n):
        x = s + w[i]
#        print("max:{} nimotu[{}]:{} + sekisai:{} = {} track:{}".format(P,i,w[i],s,x,t))
        if x > P: # ????????????
            t += 1
            st += s
            s = w[i]
#            print("next track:{} sekisai:{}".format(t,s))
            if t > k: # ??°??°????????????
#                print("\tfalse track:{}/{} s:{}".format(t,k,s))
                return st
        else:
            s = x

#    print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st))
    return 0

def main():
    """ ????????? """
    n,k = list(map(int,input().split()))
    istr = sys.stdin.read()
    wi = list(map(int,istr.splitlines()))

    # ?????§?????¨???????????¨????°????????±???????
    P = 0
    total = 0
    min = 100000
    for w in wi:
        if P < w:
            P = w
        if min > w:
            min = w
        total += w
    na = int(total / n) # ?????????????????????
    if total % n > 0:
        na += 1
    ka = int(total / k) # ???????????????????????????
    if total % k > 0:
        ka += 1
    # ?????? P (??????????????§??????????????????????????????????±?????????????
#    print("kosu:{} MAX:{} MIN:{} na:{} ka:{} total:{}".format(n, P, min, na, ka, total))
    if P < na:
        P = na
    if P < ka:
        P = ka
    z = 0
    while P <= total:
        st = kenzan(P, wi, n, k)
        if st == 0:
            a = P - z
            b = P
            break
        z = int((total-st)/k)
        P += z
    
    while b - a > 1:
#        print("P:{} MAX:{} MIN:{}".format(P, b, a))
        x = int((b - a) / 2)
        if x < 1:
            x = 1
        P = x + a
        st = kenzan(P, wi, n, k)
        if st == 0:
            b = P
        else:
            a = P

    print(P)


if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Allocation

????????????????????? wi(i=0,1,...n???1) ??? n ??????????????????
????????????????????¢????????????????????????????????????
????????????????????? k ??°?????????????????????????????????
???????????????????????£?¶??????? 0 ?????\??????????????????????????¨?????§???????????????
???????????????????????????????????????????????§????????? P ????¶????????????????????????????
?????§????????? P ?????????????????????????????§??±?????§??????

n???k???wi ???????????????????????§????????????????????????????????????????????????
?????§????????? P ???????°????????±???????????????°????????????????????????????????????

"""
import sys

# ??????????????\????????????
def kenzan(P, w, n, k):
#    print("P:{} kosu:{} track:{}".format(P,n,k))
    t = 1 # ????????????
    s = 0 # ?????????
    st = 0
    for i in range(n):
        x = s + w[i]
#        print("max:{} nimotu[{}]:{} + sekisai:{} = {} track:{}".format(P,i,w[i],s,x,t))
        if x > P: # ????????????
            t += 1
            st += s
            s = w[i]
#            print("next track:{} sekisai:{}".format(t,s))
            if t > k: # ??°??°????????????
#                print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st))
                return st
        else:
            s = x

#    print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st))
    return 0

def main():
    """ ????????? """
    n,k = list(map(int,input().split()))
    istr = sys.stdin.read()
    wi = list(map(int,istr.splitlines()))

    # ?????§?????¨???????????¨????°????????±???????
    P = 0
    total = 0
    min = 100000
    for w in wi:
        if P < w:
            P = w
        if min > w:
            min = w
        total += w
    na = int(total / n) # ?????????????????????
    if total % n > 0:
        na += 1
    ka = int(total / k) # ???????????????????????????
    if total % k > 0:
        ka += 1
    # ?????? P (??????????????§??????????????????????????????????±?????????????
#    print("kosu:{} MAX:{} MIN:{} na:{} ka:{} total:{}".format(n, P, min, na, ka, total))
    if P < na:
        P = na
    if P < ka:
        P = ka
    z = 0
    while P <= total:
        st = kenzan(P, wi, n, k)
#        print("??????????????°:{} ??????????????°??°:{} ?????????????????§??????:{} ????????????????????????:{} ??????????????????:{} ??????:{}".format(n, k, P, total, st,z))
        if st == 0:
            a = P - z
            b = P
            break
        z = int((total-st)/k)
        if z < 1:
            z = 1
        P += z
    
    while b - a > 0:
        x = int((b - a) / 2)
        if x < 1:
            a = b
        P = x + a
        st = kenzan(P, wi, n, k)
#        print("P:{} MAX:{} MIN:{} sekisai:{}".format(P, b, a, st))
        if st == 0:
            b = P
        else:
            a = P

    print(P)


if __name__ == '__main__':
    main()