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: Wrong Answer

Solution code:
def get_min_p(offset, length, k, arr):
  if k == 1: return sum(arr[offset:offset + length])
  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:
    e = len(arr) - k + 2
    p = [100] * (e)
    for i in range(1, e):
      #print("p:{}, i:{}".format(p, i))
      a = get_min_p(offset + i, length - i, k - 1, arr)
      b = sum(arr[offset:offset + i])
      p[i] = max(a, b)
    return min(p)

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

Submission status: Wrong Answer

Solution code:
def get_min_p(offset, length, k, arr):
  if k == 1: return sum(arr[offset:offset + length])
  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:
    e = len(arr) - k + 2
    p = [100] * (e)
    for i in range(1, e):
      #print("p:{}, i:{}".format(p, i))
      a = get_min_p(offset + i, length - i, k - 1, arr)
      b = sum(arr[offset: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: Wrong Answer

Solution code:
import sys
n, k = map(int, input().split())
w = tuple(map(int, sys.stdin.readlines()))
p = max(w)
if n <= k:
    print(p)
else:
    a = max(p, sum(w)//k+1)
    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: Wrong Answer

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

def check(p):
    c = t = 0
    for wi in w:
        t += wi
        if t > p:
            t = wi
            c += 1
            if c >= k:
                return False
    return True

s = max(w)
l = sum(w)
while s < l:
    m = (s+l)//2
    if check(m):
        l = m
    else:
        s = m+1
print(m)

Submission status: Wrong Answer

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

def check(p):
    c = t = 0
    for wi in w:
        t += wi
        if t > p:
            t = wi
            c += 1
            if c >= k:
                return False
    return True

s = max(w)
l = sum(w)
while s == l:
    m = (s+l)//2
    if check(m):
        l = m
    else:
        s = m = m+1
print(s)

Submission status: Wrong Answer

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

def func(p):
    return k*p

p = 1
while True:
    if func(p) > sum:
        print(p)
        break
    else:
        p += 1

Submission status: Wrong Answer

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

def func(p):
    return k*p

p = 1
while True:
    if func(p) >= sum:
        print(p)
        break
    else:
        p += 1

Submission status: Wrong Answer

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 = (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: Wrong Answer

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: Wrong Answer

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, pmin):
			p = pmin
		else:
			p = pmax
		break

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

print(p)

Submission status: Wrong Answer

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):
            right = middle 
        else:
            left = middle + 1
    return left
            
def hantei(t,w,p):
    track_on = 0
    daisu = 1
    for j in range(len(w)):     
        track_on += w[j]
        if track_on > p:
            daisu += 1
            track_on = w[j]
            if daisu > t:
                return False
    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: Wrong Answer

Solution code:
n, k = map(int, input().split())
w = [int(input()) for i in range(n)]
w.reverse()
P = max((sum(w) // k) , max(w))
while True:
    carcnt = 0
    while w != []:
        wgtcnt = 0
        while w != [] and wgtcnt + w[-1] <= P:
            wgtcnt += w.pop()
        carcnt += 1
    if carcnt <= k:
        print(P)
        break
    else:
        P += 1

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
weight = []
for i in range(n):
    weight.append(int(input()))
tmp_numberOfGroup = 0
tmp_p = max(weight) - 1
while tmp_numberOfGroup+1 != k:
    tmp_p += 1
    tmp_weight = 0
    tmp_numberOfGroup = 0
    for tmp_w in weight:
        if tmp_w+tmp_weight > tmp_p:
            tmp_numberOfGroup += 1
            tmp_weight = tmp_w
        else:
            tmp_weight += tmp_w

print(tmp_p)

Submission status: Wrong Answer

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] = int(input())

w.sort()
w.reverse()

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

print(max(sumw))

Submission status: Wrong Answer

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] = int(input())

w.sort()
w.reverse()

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

print(max(sumw))
#print(*sumw)

Submission status: Wrong Answer

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

import sys
import os


n, k = map(int, input().split())
#print(k, '??°??§????????????')

W = []
for i in range(n):
    W.append(int(input()))

def check(P):
    # ?????????P?????\?????¨??????????????????????????????????????????????????¢??°
    weight_index = 0
    for i in range(k):
        current_weight = 0
        while current_weight + W[weight_index] <= P:
            #print('i', i, W[weight_index], '?????????')
            current_weight += W[weight_index]
            weight_index += 1
            if weight_index == len(W):
                # ??¨??¨?????£???
                return len(W)
    return weight_index

P_min = 1
P_max = 100000 * 10000
P_mid = None
while True:
    P_mid = (P_min + P_max) // 2
    loaded_num = check(P_mid)

    if loaded_num < n:
        # ????????????????????????
        P_min = P_mid
    else:
        # ??????????????????????????§???P??????????????¢???
        P_max = P_mid

    if P_max - P_min <= 1:
        #print('?????????', P_max, P_mid, P_min)
        break

print(P_max)

Submission status: Wrong Answer

Solution code:
import math
n, k = map(int, input().split())
a = [int(input()) for _ in [None]*n]

lb = max(a)
ub = lb * n

while ub > lb+0.5:
    mid = (ub+lb) / 2
    remain = k - 1
    cw = 0
    for w in a:
        cw += w
        if cw > mid:
            remain -= 1
            cw = w
        if remain < 0:
            break
    if remain < 0:
        lb = mid
    else:
        ub = mid

print(math.ceil(mid-0.49))

Submission status: Wrong Answer

Solution code:
from math import ceil
s = input().split(" ")
n = int(s[0])
k = int(s[1])
w = []
total = 0
for i in range(n):
    a = int(input())
    w.append(a)
    total += a
mx = ceil(total / k)
while True:
    t = []
    t.append(w[0])
    for i in range(1,len(w)):
        if t[len(t)-1] + w[i] <= mx:
            t[len(t)-1] += w[i]
        else:
            t.append(w[i])
            if len(t) > k:
                break
    if len(t) > k:
        mx += 1
    else:
        break
print(mx)

Submission status: Wrong Answer

Solution code:
#ALDS1_4-D Allocation
import collections
print(6)

Submission status: Wrong Answer

Solution code:
import collections
print(1)

Submission status: Wrong Answer

Solution code:
import collections
w = collections.deque()
print(w)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
from collections import deque

w = deque()

Submission status: Wrong Answer

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: Wrong Answer

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: Wrong Answer

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: Wrong Answer

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
        if c+1>k:return False
    return True
    
n,k = input().split()
w = []
for i in range(int(n)):
    w.append(int(input()))

#p = max(w)
p=0

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

Submission status: Wrong Answer

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
        if c+1>k:return False
    return True
    
n,k = input().split()
w = []
for i in range(int(n)):
    w.append(int(input()))

#p = max(w)
p=1

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

Submission status: Wrong Answer

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
        if c+1>k:return False
    return True
    
n,k = input().split()
w = []
for i in range(int(n)):
    w.append(int(input()))

#p = max(w)
p=10

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

Submission status: Wrong Answer

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
        if c+1>k:return False
    return True
    
n,k = input().split()
w = []
for i in range(int(n)):
    w.append(int(input()))

p = max(w)

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

Submission status: Wrong Answer

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
        if c+1>k:return False
    return True
    
n,k = [int(x) for x in input().split()]
w = []
for i in range(n):
    w.append(int(input()))

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

Submission status: Wrong Answer

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
        if c+1>k:return False
    return True
    
n,k = [int(x) for x in input().split()]
w = []
for i in range(n):
    w.append(int(input()))

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

Submission status: Wrong Answer

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
        if c+1>k:return False
    return True
    
n,k = [int(x) for x in input().split()]
w = []
for i in range(n):
    w.append(int(input()))

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

Submission status: Wrong Answer

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
        if c+1>k:return False
    return True
    
n,k = [int(x) for x in input().split()]
w = []
for i in range(n):
    w.append(int(input()))

p = int(sum(w)/k)+1
if(sum(w)%k==0):p-=1
while(1):
    x=deque(w)
    if(pIsAccptbl(x,k,p)):
        print(p)
        break
    else:
        p+=1

Submission status: Wrong Answer

Solution code:
from collections import deque

def cndP(w,n,p1,p2):
    s=set()
    d = deque(w)
    while(True):
        a=d.popleft()
        b=d.popleft()
        c=a+b
        if p2 == None:
            if p1 < c:s.add(c)
        else:
            if p1 < c < p2:s.add(c)
        if not d:
            break
        else:
            d.appendleft(b)
    return sorted(s)

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=1
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
            p1 = i

Submission status: Wrong Answer

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 = []
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: Wrong Answer

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 = []
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
            p1 = i
        n+=1

Submission status: Wrong Answer

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 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()]

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
            p1 = i
        n+=1

Submission status: Wrong Answer

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()]

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: Wrong Answer

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()

Submission status: Wrong Answer

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()))

Submission status: Wrong Answer

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()

Submission status: Wrong Answer

Solution code:
from collections import deque

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(w)
        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
    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)
sorted_st = sorted(st)
for i in sorted_st:
    if pIsAccptbl(w,k,i):
        print(i)
        break

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
sys.setrecursionlimit(100000)


def copyDeque(d):
    x = deque()
    for i in d:
        x.append(i)
    return x

def cndP(w):
    if len(w)>1:
        x = w.pop()
        cndP(copyDeque(w))
        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 = copyDeque(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([int(x) for x in input().split()])

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

sorted_st = sorted(st)
for i in sorted_st:
    if pIsAccptbl(w,k,i):
        print(i)
        break

Submission status: Wrong Answer

Solution code:
from collections import deque

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

def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)
l = range(mean,maxinp)

for i in range(mean,maxinp+1):
    if(pIsAccptbl(w,k,i)):
        print(i)
        break

Submission status: Wrong Answer

Solution code:
from collections import deque

def isPa(w,k,p):
    counter = 0
    s = 0
    n = 1
    wlen = len(w)
    while(True):
        if( sum(w[s:s+n]) >= p):
            if( s+n == wlen):
                counter+=1
                break
            s = s+n-1
            n = 1
            counter += 1
        else:
            if( s+n == wlen):
                counter += 1
                break
            n += 1
    if(counter > k):
        return False
    else:
        return True
    
def MaxInP(w,k,p):
    maxinp = 0
    s = 0
    n = 1
    wlen = len(w)
    while(True):
        if( sum(w[s:s+n]) >= p):
            if( sum(w[s:s+n]) > maxinp):
                maxinp = sum(w[s:s+n])
            if( s+n == wlen):
                if( w[-1] > maxinp):
                    maxinp = w[-1]
                break
                
            s = s+n
            n = 1
        else:
            n += 1
            if( s+n == wlen):
                if( sum(w[s:s+n]) > maxinp):
                    maxinp = sum(w[s:s+n])
                break
    return maxinp

n,k = [int(x) for x in input().split()]
w = []
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP==maxP):
            print(maxP)
            break

Submission status: Wrong Answer

Solution code:
from collections import deque

def isPa(w,k,p):
    counter = 0
    s = 0
    n = 1
    wlen = len(w)
    while(True):
        if( sum(w[s:s+n]) >= p):
            if( s+n == wlen):
                counter+=1
                break
            s = s+n-1
            n = 1
            counter += 1
        else:
            if( s+n == wlen):
                counter += 1
                break
            n += 1
    if(counter > k):
        return False
    else:
        return True
    
def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = []
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP==maxP):
            print(maxP)
            break