Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

  You are given $n$ packages of $w_i$ kg from a belt conveyor in order ($i = 0, 1, ... n-1$). You should load all packages onto $k$ trucks which have the common maximum load $P$. Each truck can load consecutive packages (more than or equals to zero) from the belt conveyor unless the total weights of the packages in the sequence does not exceed the maximum load $P$. 

  Write a program which reads $n$, $k$ and $w_i$, and reports the minimum value of the maximum load $P$ to load all packages from the belt conveyor.

Input

  In the first line, two integers $n$ and $k$ are given separated by a space character. In the following $n$ lines, $w_i$ are given respectively.

Output

  Print the minimum value of $P$ in a line.

Constraints

 $1 \leq n \leq 100,000$

 $1 \leq k \leq 100,000$

 $1 \leq w_i \leq 10,000$

Sample Input 1

5 3
8
1
7
3
9

Sample Output 1

10

    If the first truck loads two packages of $\{8, 1\}$, the second truck loads two packages of $\{7, 3\}$ and the third truck loads a package of $\{9\}$, then the minimum value of the maximum load $P$ shall be 10.

Sample Input 2

4 2
1
2
2
6

Sample Output 2

6

    If the first truck loads three packages of $\{1, 2, 2\}$ and the second truck loads a package of $\{6\}$, then the minimum value of the maximum load $P$ shall be 6.



Sample input:
5 3
8
1
7
3
9


Sample output:
10

Submission status: Runtime Error

Solution code:
import sys
import math

def is_capable(n, k, w, P):
    track = 0
    cnt = 0
    i = 0

    while cnt < k:
        if i == n:
            return True

        if track + w[i] > P:
            track = 0
            cnt += 1
        else:
            track += w[i]
            i += 1

    return False
    pass

# ??\?????¨
n, k = map(int, sys.stdin.readline().split())
w = []
for i in range(n):
    w.append(int(sys.stdin.readline().strip()))

'''
print(n,k)
print(w)
'''

# ????????¨

if k == 1:
    ans = sum(w)
    print(ans)
elif n == 1:
    ans = w[0]
    print(ans)
else:
    max_p = sum(w)
    min_p = math.ceil(max_p / k) - 1

    capable = [None] * (max_p - min_p + 1)
    capable[0] = False
    capable[-1] = True

    bottom = 0
    top = len(capable)

    while bottom < top:
        mid = (bottom + top) // 2

        if capable[mid] is None:
            capable[mid] = is_capable(n, k, w, min_p + mid)

        if capable[mid] == True:
            if capable[mid - 1] is None:
                capable[mid - 1] = is_capable(n, k, w, min_p + mid - 1)

            if capable[mid - 1] == False:
                bnd = mid
                break
            else:
                top = mid - 1
        elif capable[mid] == False:
            if capable[mid + 1] is None:
                capable[mid + 1] = is_capable(n, k, w, min_p + mid + 1)

            if capable[mid + 1] == True:
                bnd = mid + 1
                break
            else:
                bottom = mid + 2

    ans = min_p + bnd

    print(ans)
    # print(capable)

Submission status: Runtime Error

Solution code:
def get_min_p(offset, length, k, arr):
  if k == 2:
    min_diff = 100
    p = 0
    for i in range(1, length):
      a = sum(arr[offset:offset + i])
      b = sum(arr[offset + i:])
      if abs(a - b) < min_diff:
        min_diff = abs(a - b)
        p = max(a, b)
      #print("arr:{}, i:{}, p:{}".format(
      #  arr[offset:offset + length], i, p))
    return p
  else:
    p = [100] * (len(arr) - k + 2)
    for i in range(1, len(arr) - k + 2):
      #print("p:{}, i:{}".format(p, i))
      a = get_min_p(offset + i, length - i, k - 1, arr)
      b = sum(arr[:offset + i])
      p[i] = max(a, b)
    return min(p)

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

print(get_min_p(0, n, k, a))

Submission status: Runtime Error

Solution code:
import sys
n, k = map(int, input().split())
w = tuple(map(int, sys.stdin.readlines()))
w = tuple(map(int, input().split()))
p = max(w)
s = sum(w)
if n <= k:
    print(p)
elif k == 1:
    print(s)
else:
    a = max(p, s//k)
    while True:
        l = [a]
        for i in range(n):
            d = l[-1] - w[i]
            if d < 0:
                l.append(a-w[i])
            else:
                l[-1] = d
            i += 1
        if len(l) > k:
            a += 1
        else:
            break
    print(a)

Submission status: Runtime Error

Solution code:
import sys
import math 

def be_able_to_convey(w, k, p):
	counter = 0
	cur_weight = 0
	for wi in w:
		if wi > p:
			return False

		cur_weight += wi
		if(cur_weight > p):
			cur_weight = wi
			counter += 1
			if(counter >= k):
				return False

	return True

fin = open("test.txt", "r")
#fin = sys.stdin

n, k = map(int, fin.readline().split())
w = [0 for i in range(n)]
w_max = 0

for i in range(n):
	w[i] = int(fin.readline())
	w_max = max(w[i], w_max)
	

pmin = 1
pmax = math.ceil(w_max * w_max // k)

while pmin < pmax:
	p = math.ceil((pmin + pmax) / 2)
	if p == pmin or p == pmax:
		if be_able_to_convey(w, k, pmax):
			if be_able_to_convey(w, k, pmin):
				p = pmin
			else:
				p = pmax
		else:
			p = pmin
		break

	if not be_able_to_convey(w, k, p):
		pmin = p
	else:
		pmax = p

print(p)

Submission status: Runtime Error

Solution code:
import sys

def binarySearch(t,w,p):
    left = 0
    right = p
    while left < right:
        middle = (left + right) // 2
        if hantei(t,w,middle):
            left = middle + 1
        else:
            right = middle
    return left
            
def hantei(t,w,p):
    track_on = [0]*t
    j = 0
    for i in range(t):
        temp = track_on[i]
        while True:
            temp += w[j]
            if temp > p:
                break
            else:
                if j == len(w):
                    return False
                track_on[i] = temp
                j += 1
    return True


nimotsu, track = map(int,input().split())
weight = list(map(int,sys.stdin.readlines()))


max_p = sum(weight) // track + 1

print(binarySearch(track,weight,max_p))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


def check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, maximum_weight):
    """check the numbers that are loadable in tracks
    
    Args:
        cargo_weight_list: cargo weight list
        number_of_tracks: the number of tracks
        
    Returns:
        the number of cargos that are loadable in tracks
    """
    counter = 0
    number_of_loaded_cargo = 0
    weight_iter = iter(cargo_weight_list)

    while counter < number_of_tracks:
        current_track_weight = 0
       
        next_weight = weight_iter.next()
        while current_track_weight + next_weight <= maximum_weight:
            current_track_weight += next_weight
            number_of_loaded_cargo += 1
            if number_of_loaded_cargo == number_of_all_cargo:
                return number_of_all_cargo
            else:
                next_weight = weight_iter.next()

        counter += 1

    return number_of_loaded_cargo


def find_the_minimum_of_maximum_weihgt(cargo_weight_list, number_of_all_cargo, number_of_tracks):
    """find the minimum of maximum weight s.t all of the cargos can be loaded into tracks.
    (binary search is used. the number of loadable cargos monotonicaly increases as the maximum weight increases)


    Args:
        cargo_weight_list: cargo weight list
        numbef of all cargo: the number of all cargos
        number of tracks: the number of tracks

    Returns:
        minumim number of maximum track weight that are needed to load all of the cargos
    """
    left = max(cargo_weight_list)
    right = sum(cargo_weight_list)
    while (right - left) > 0:
        middle = (right + left) / 2
        the_number_of_loadable_cagos = check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, middle)
        if the_number_of_loadable_cagos >= number_of_all_cargo:
            right = middle
        else:
            left = middle + 1

    return right

def main():
    number_of_all_cargo, number_of_tracks = [int(x) for x in raw_input().split(' ')]
    cargo_weight_list = [int(raw_input()) for _ in xrange(number_of_all_cargo)]
    
    print find_the_minimum_of_maximum_weihgt(cargo_weight_list, number_of_all_cargo, number_of_tracks)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-


def check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, maximum_weight):
    """check the numbers that are loadable in tracks
    
    Args:
        cargo_weight_list: cargo weight list
        number_of_tracks: the number of tracks
        
    Returns:
        the number of cargos that are loadable in tracks
    """
    counter = 0
    number_of_loaded_cargo = 0
    weight_iter = iter(cargo_weight_list)

    while counter < number_of_tracks:
        current_track_weight = 0
       
        next_weight = weight_iter.next()
        while current_track_weight + next_weight <= maximum_weight:
            current_track_weight += next_weight
            number_of_loaded_cargo += 1
            if number_of_loaded_cargo == number_of_all_cargo:
                return number_of_all_cargo
            else:
                next_weight = weight_iter.next()

        counter += 1

    return number_of_loaded_cargo


def find_the_minimum_of_maximum_weihgt(cargo_weight_list, number_of_all_cargo, number_of_tracks):
    """find the minimum of maximum weight s.t all of the cargos can be loaded into tracks.
    (binary search is used. the number of loadable cargos monotonicaly increases as the maximum weight increases)


    Args:
        cargo_weight_list: cargo weight list
        numbef of all cargo: the number of all cargos
        number of tracks: the number of tracks

    Returns:
        minumim number of maximum track weight that are needed to load all of the cargos
    """
    left = max(cargo_weight_list)
    right = sum(cargo_weight_list)
    while (right - left) > 0:
        middle = (right + left) / 2
        the_number_of_loadable_cagos = check_numbers(cargo_weight_list, number_of_all_cargo, number_of_tracks, middle)
        if the_number_of_loadable_cagos >= number_of_all_cargo:
            right = middle
        else:
            left = middle + 1

    return right

def main():
    number_of_all_cargo, number_of_tracks = [int(x) for x in raw_input().split(' ')]
    cargo_weight_list = [int(raw_input()) for _ in xrange(number_of_all_cargo)]
    
    print find_the_minimum_of_maximum_weight(cargo_weight_list, number_of_all_cargo, number_of_tracks)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
w = [0 for i in range(n)]
sumw = [0 for i in range(k)]
for i in range(n):
    w[i] = input()

w.sort()
w.reverse()

for i in range(w):
    sumw[min(sumw.index)] += w[i]

print(min(sumw))

Submission status: Runtime Error

Solution code:
#ALDS1_4-D Allocation
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = 0
            c += 1
        else:
            tr += tmp
    c+=1
    if c>k:return False
    else:return True
    
n,k = input().split()
w = []
w = deque()
for i in range(int(n)):
    w.append(int(input()))

p = max(w)

while(1):
    x=w.copy()
    if(pIsAccptbl(x,int(k),p)):
        print(p)
        break
    else:
        p+=1

Submission status: Runtime Error

Solution code:
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        print(c,tr)
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:return False
    else:return True
    
n,k = input().split()
w = []
w = deque()
for i in range(int(n)):
    w.append(int(input()))

p = max(w)

while(1):
    x=w.copy()
    print("p",p)
    if(pIsAccptbl(x,int(k),p)):
        print(p)
        break
    else:
        p+=1

Submission status: Runtime Error

Solution code:
#ALDS1_4-D Allocation
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        print(c,tr)
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:return False
    else:return True
    
n,k = input().split()
w = []
w = deque()
for i in range(int(n)):
    t = input()
    w.append(int(t))

p = max(w)

while(1):
    x=w.copy()
    print("p",p)
    if(pIsAccptbl(x,int(k),p)):
        print(p)
        break
    else:
        p+=1

Submission status: Runtime Error

Solution code:
#ALDS1_4-D Allocation
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:return False
    else:return True
    
n,k = input().split()
w = []
w = deque()
for i in range(int(n)):
    t = input()
    w.append(int(t))

p = max(w)

while(1):
    x=w.copy()
    if(pIsAccptbl(x,int(k),p)):
        break
    else:
        p+=1

Submission status: Runtime Error

Solution code:
#ALDS1_4-D Allocation
import collections

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:return False
    else:return True
    
n,k = input().split()
w = collections.deque()
for i in range(int(n)):
    w.append(int(input()))

p = max(w)

while(1):
    x=w.copy()
    if(pIsAccptbl(x,int(k),p)):
        break
    else:
        p+=1

Submission status: Runtime Error

Solution code:
from collectins import deque

Submission status: Runtime Error

Solution code:
from collectins import deque
print(1)

Submission status: Runtime Error

Solution code:
#ALDS1_4-D Allocation
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:
        return False
    else:
        return True
    
n,k = input().split()
w = collections.deque()
for i in range(int(n)):
    w.append(int(input()))

p = max(w)

while(1):
    x=w.copy()
    if(pIsAccptbl(x,int(k),p)):
        print(p)
        break
    else:
        p+=1

Submission status: Runtime Error

Solution code:
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:
        return False
    else:
        return True
    
n,k = input().split()
w = collections.deque()
for i in range(int(n)):
    w.append(int(input()))

p = max(w)
'''
while(1):
    x=w.copy()
    if(pIsAccptbl(x,int(k),p)):
        print(p)
        break
    else:
        p+=1
'''

Submission status: Runtime Error

Solution code:
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:
        return False
    else:
        return True
    
n,k = input().split()
w = collections.deque()
'''
for i in range(int(n)):
    w.append(int(input()))

p = max(w)

while(1):
    x=w.copy()
    if(pIsAccptbl(x,int(k),p)):
        print(p)
        break
    else:
        p+=1
'''

Submission status: Runtime Error

Solution code:
from collections import deque

w = collections.deque()

Submission status: Runtime Error

Solution code:
#ALDS1_4-D Allocation
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:
        return False
    else:
        return True
    
n,k = input().split()
w = deque()
for i in range(int(n)):
    w.append(int(input()))

p = max(w)

while(1):
    x=w.copy()
    if(pIsAccptbl(x,int(k),p)):
        print(p)
        break
    else:
        p+=1

Submission status: Runtime Error

Solution code:
#ALDS1_4-D Allocation
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:
        return False
    else:
        return True
    
n,k = input().split()
w = deque()

for i in range(int(n)):
    w.append(int(input()))

p = max(w)

while(1):
    x=w.copy()
    '''
    if(pIsAccptbl(x,int(k),p)):
        print(p)
        break
    else:
        p+=1
    '''
    break

Submission status: Runtime Error

Solution code:
#ALDS1_4-D Allocation
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:
        return False
    else:
        return True
    
n,k = input().split()
w = deque()

for i in range(int(n)):
    w.append(int(input()))

p = max(w)

while(1):
    x=deque()
    x=w.copy()
    
    if(pIsAccptbl(x,int(k),p)):
        print(p)
        break
    else:
        p+=1

Submission status: Runtime Error

Solution code:
from collections import deque

def cndP(l,n,p1,p2):
    d = set()
    length = len(l)
    for i in range(length-n+1):
        s = sum(l[i:i+n])
        #print("s:",s)
        if p2 == None:
            if p1 < s:
                d.add(s)
        else:
            if p1 < c < p2:
                d.add(s)
    return sorted(d)

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = []
for i in range(n):
    e = int(input())
    w.append(e)

n=2
p = max(w)
p1 = p
p2 = None

if(pIsAccptbl(w,k,p)):
    print(p)
else:
    while(1):
        #print("p1,p2:",p1,p2)
        s = cndP(w,n,p1,p2)
        #print("s:",s)
        if s==[]:
            #print(p2)
            break;
        for i in s:
            if(pIsAccptbl(w,k,i)):
                p2 = i
                break
            p1 = i
        n+=1

Submission status: Runtime Error

Solution code:
from collections import deque

def cndP(l,n,p1,p2):
    d = set()
    length = len(l)
    for i in range(length-n+1):
        s = sum(l[i:i+n])
        if p2 == None:
            if p1 < s:
                d.add(s)
        else:
            if p1 < c < p2:
                d.add(s)
    return sorted(d)

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = []
for i in range(n):
    e = int(input())
    w.append(e)

n=2
p = max(w)
p1 = p
p2 = None

if(pIsAccptbl(w,k,p)):
    print(p)
else:
    while(1):
        s = cndP(w,n,p1,p2)
        if s==[]:
            break;
        for i in s:
            if(pIsAccptbl(w,k,i)):
                p2 = i
                break
            p1 = i
        n+=1

Submission status: Runtime Error

Solution code:
from collections import deque

def cndP(l,n,p1,p2):
    d = set()
    length = len(l)
    for i in range(length-n+1):
        s = sum(l[i:i+n])
        if p2 == None:
            if p1 < s:
                d.add(s)
        else:
            if p1 < s < p2:
                d.add(s)
    return sorted(d)

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
#w = [int(x) for x in input().split()]
for i in range(n):
    e = int(input())
    w.append(e)
    
n=2
p = max(w)
p1 = p
p2 = None

if(pIsAccptbl(w,k,p)):
    print(p)
else:
    while(1):
        s = cndP(w,n,p1,p2)
        if s==[]:
            print(p2)
            break;
        for i in s:
            if(pIsAccptbl(w,k,i)):
                p2 = i
                break
            if(p2==None):
                p1 = i
        n+=1

Submission status: Runtime Error

Solution code:
from collections import deque

def cndP(l,n,p1,p2):
    d = set()
    length = len(l)
    for i in range(length-n+1):
        s = sum(l[i:i+n])
        if p2 == None:
            if p1 < s:
                d.add(s)
        else:
            if p1 < s < p2:
                d.add(s)
    return sorted(d)

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
for i in range(n):
    e = int(input())
    w.append(e)
    
n=2
p = max(w)
p1 = p
p2 = None

if(pIsAccptbl(w,k,p)):
    print(p)
else:
    while(1):
        s = cndP(w,n,p1,p2)
        if s==[]:
            print(p2)
            break;
        for i in s:
            if(pIsAccptbl(w,k,i)):
                p2 = i
                break
            if(p2==None):
                p1 = i
        n+=1

Submission status: Runtime Error

Solution code:
from collections import deque

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(w.copy())
        w.append(x)
        s = 0
        while(len(w)>0):
            s += w.pop()
            st.add(s)
    else:
        st.add(w[0])
        
def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = w.copy()
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()

for i in range(n):
    w.append(int(input()))
    
st = set()
cndP(w.copy())
sorted_st = sorted(st)
for i in sorted_st:
    if pIsAccptbl(w,k,i):
        print(i)
        break

Submission status: Runtime Error

Solution code:
from collections import deque

def cndP(l,n,p1,p2):
    d = set()
    min = sum(l[:])
    length = len(l)
    for i in range(length-n+1):
        s = sum(l[i:i+n])
        if s < min:
            min = s
        if p2 == None:
            if p1 < s:
                d.add(s)
        else:
            if p1 < s < p2:
                d.add(s)
    d.add(min)
    return sorted(d)

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))

p = max(w)

if(pIsAccptbl(w,k,p)):
    print(p)
else:
    n=2
    p1 = p
    p2 = None
    while(1):
        s = cndP(w,n,p1,p2)
        if not p2 == None:
            if s[0] > p2:
                print(p2)
                break
        for i in s:
            if(pIsAccptbl(w,k,i)):
                p2 = i
                break
            if(p2==None):
                p1 = i
        if (n == len(w)):
            print(p2)
            break
        n+=1

Submission status: Runtime Error

Solution code:
from collections import deque

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(w.copy())
        w.append(x)
        s = 0
        while(len(w)>0):
            s += w.pop()
            st.add(s)
    else:
        st.add(w[0])
        
def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = w.copy()
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()

for i in range(n):
    w.append(int(input()))
    
st = set()
cndP(w.copy())
sorted_st = sorted(st)

Submission status: Runtime Error

Solution code:
from collections import deque

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(w.copy())
        w.append(x)
        s = 0
        while(len(w)>0):
            s += w.pop()
            st.add(s)
    else:
        st.add(w[0])
        
def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = w.copy()
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()

for i in range(n):
    w.append(int(input()))
    
st = set()
cndP(w.copy())

Submission status: Runtime Error

Solution code:
from collections import deque

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(w.copy())
        w.append(x)
        s = 0
        while(len(w)>0):
            s += w.pop()
            st.add(s)
    else:
        st.add(w[0])
        
def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = w.copy()
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()

for i in range(n):
    w.append(int(input()))
    
st = set()
from collections import deque

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(w.copy())
        w.append(x)
        s = 0
        while(len(w)>0):
            s += w.pop()
            st.add(s)
    else:
        st.add(w[0])
        
def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = w.copy()
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()

for i in range(n):
    w.append(int(input()))
    
st = set()
cndP(w.copy())

Submission status: Runtime Error

Solution code:
from collections import deque

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(w.copy())
        w.append(x)
        s = 0
        while(len(w)>0):
            s += w.pop()
            st.add(s)
    else:
        st.add(w[0])
        
def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = w.copy()
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()

for i in range(n):
    w.append(int(input()))
    
st = set()
from collections import deque

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(w.copy())
        w.append(x)
        s = 0
        while(len(w)>0):
            s += w.pop()
            st.add(s)
    else:
        st.add(w[0])
        
def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = w.copy()
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()

for i in range(n):
    w.append(int(input()))
    
st = set()
cndP(w)

Submission status: Runtime Error

Solution code:
from collections import deque

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(w.copy())
        w.append(x)
        s = 0

    else:
        st.add(w[0])
        
def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = w.copy()
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()

for i in range(n):
    w.append(int(input()))
    
st = set()
from collections import deque

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(w.copy())
        w.append(x)
        s = 0
        while(len(w)>0):
            s += w.pop()
            st.add(s)
    else:
        st.add(w[0])
        
def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = w.copy()
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()

for i in range(n):
    w.append(int(input()))
    
st = set()
cndP(w.copy)

Submission status: Runtime Error

Solution code:
from collections import deque

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(w.copy())

    else:
        st.add(w[0])
        
def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = w.copy()
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()

for i in range(n):
    w.append(int(input()))
    
st = set()
from collections import deque

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(w.copy())
        w.append(x)
        s = 0
        while(len(w)>0):
            s += w.pop()
            st.add(s)
    else:
        st.add(w[0])
        
def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    d = w.copy()
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

n,k = [int(x) for x in input().split()]
w = deque()

for i in range(n):
    w.append(int(input()))
    
st = set()
cndP(w.copy)