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 Is_ToPut(p,w,k):
    if w/p <=k:return 1
    else:return 0

n,k = list(map(int,input().split(' ')))
item =[]
for _ in range(n):
    item.append(int(input()))
ans =100000*10000
w = sum(item)
left = 0
right = 100000*10000
while left < right:
    p = (left+right)//2
    if Is_ToPut(p,w,k):
        if ans > p:
            ans =p
        right=p
    else:
        left = p +1
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
klist = []
for i in range(n):
    klist.append(int(input()))
kk = [0for i in range(k)]
klist = sorted(klist, reverse = True)
for i in range(n):
    c = 0
    p = 0
    while (c == 0):
        if (min(kk) == kk[p]):
            kk[p] = kk[p] + klist[i]
            c = 1
        else:
            p += 1
print(max(kk))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l = list(int(input()) for i in range(n))

left = max(l); right = sum(l)

while left+1 < right:  #最大値と合計値の間のどこかに考えるべき値が存在する
    mid = (left + right) // 2
    cnt = 1; cur = 0  #初期化
    for a in l:
        if mid < cur + a:
            cur = a
            cnt += 1
        else:
            cur += a

    if cnt <= k:
        right = mid
    else:
        left = mid

print(right)

Submission status: Wrong Answer

Solution code:
def check(P):
    for i, bag in enumerate(baggage):
        cur = 0
        while su(cur) + bag > P:
            cur += 1
        if cur == k:
            return False
        else:
            lis[cur].append(bag)
            su[cur] += bag
    return True
def main():
    n, k = map(int, input().rstrip().split(" "))
    lis = [[] for i in range(k)]
    su = [0 for i in range(k)]
    baggage = [int(input()) for i in range(n)]
    su.append(-1)
    
    left = 1
    right = 1000000000
    while left < right:
        mid = (left + right)//2 + 1
        if check(mid):
            right = mid
        else:
            left = mid
    
    print(right)

Submission status: Wrong Answer

Solution code:
def check(P):
    lis = [[] for i in range(k)]
    su = [0 for i in range(k)]
    
    su.append(-10000)
    for i, bag in enumerate(baggage):
        cur = 0
        #print(su,cur,su[cur])
        while su[cur] + bag > P:
            cur += 1
        if cur == k:
            return False
        else:
            lis[cur].append(bag)
            su[cur] += bag
    print(lis, su, P)
    return True

def main():
    min_P = 1000000000
    left = 1
    right = 1000000000
    while left < right:
        mid = (left + right)//2 + 1
        #print(left, mid, right, end=" ")
        if check(mid):
            right = mid
            if min_P > mid:
                min_P = mid
        else:
            left = mid+1
    
    #print(left,right)
    print(min_P)
       
if __name__ == '__main__':
    n, k = map(int, input().rstrip().split(" "))
    #n,k= 5,3
    baggage = [int(input()) for i in range(n)]
    #baggage = [8,1,7,3,9]
    
    main()

Submission status: Wrong Answer

Solution code:
def check(P):
    lis = [[] for i in range(k)]
    su = [0 for i in range(k)]
    
    su.append(-10000)
    for i, bag in enumerate(baggage):
        cur = 0
        #print(su,cur,su[cur])
        while su[cur] + bag > P:
            cur += 1
        if cur == k:
            return False
        else:
            lis[cur].append(bag)
            su[cur] += bag
    #print(lis, su, P)
    return True

def main():
    min_P = 1000000000
    left = 1
    right = 1000000000
    while ((left + right)//2 + 1) < right:
        mid = (left + right)//2 + 1
        #print(left, mid, right, end=" ")
        if check(mid):
            right = mid
            if min_P > mid:
                min_P = mid
        else:
            left = mid+1
    
    #print(left,right)
    print(min_P)
       
if __name__ == '__main__':
    n, k = map(int, input().rstrip().split(" "))
    #n,k= 5,3
    baggage = [int(input()) for i in range(n)]
    #baggage = [8,1,7,3,9]
    
    main()

Submission status: Wrong Answer

Solution code:
def check(P):
    lis = [[] for i in range(k)]
    su = [0 for i in range(k)]
    
    su.append(-10000)
    for i, bag in enumerate(baggage):
        cur = 0
        #print(su,cur,su[cur])
        while su[cur] + bag > P:
            cur += 1
        if cur == k:
            return False
        else:
            lis[cur].append(bag)
            su[cur] += bag
    #print(lis, su, P)
    return True

def main():
    min_P = 1000000000
    left = 1
    right = 1000000000
    while ((left + right)//2 + 1) < right:
        mid = (left + right)//2 + 1
        #print(left, mid, right, end=" ")
        if check(mid):
            right = mid
            if min_P > mid:
                min_P = mid
        else:
            left = mid
    
    #print(left,right)
    print(min_P)
       
if __name__ == '__main__':
    n, k = map(int, input().rstrip().split(" "))
    #n,k= 5,3
    baggage = [int(input()) for i in range(n)]
    #baggage = [8,1,7,3,9]
    
    main()

Submission status: Wrong Answer

Solution code:
def check(P):
    lis = [[] for i in range(k)]
    su = [0 for i in range(k)]
    
    su.append(-10000)
    for i, bag in enumerate(baggage):
        cur = 0
        #print(su,cur,su[cur])
        while su[cur] + bag > P:
            cur += 1
        if cur == k:
            return False
        else:
            lis[cur].append(bag)
            su[cur] += bag
    #print(lis, su, P)
    return True

def main():
    min_P = 1000000000
    left = 1
    right = 1000000000
    while  left < right-1:
        if (left + right) % 2 == 0:
            mid = (left + right)//2
        else:
            mid = (left + right)//2 + 1
        print(left, mid, right, end=" ")
        if check(mid):
            right = mid
            if min_P > mid:
                min_P = mid
        else:
            left = mid
    
    #print(left,right)
    print(min_P)
if __name__ == '__main__':
    n, k = map(int, input().rstrip().split(" "))
    #n,k= 5,3
    baggage = [int(input()) for i in range(n)]
    #baggage = [8,1,7,3,9]
    
    main()

Submission status: Wrong Answer

Solution code:
def check(P):
    lis = [[] for i in range(k)]
    su = [0 for i in range(k)]
    
    su.append(-10000)
    for i, bag in enumerate(baggage):
        cur = 0
        #print(su,cur,su[cur])
        while su[cur] + bag > P:
            cur += 1
        if cur == k:
            return False
        else:
            lis[cur].append(bag)
            su[cur] += bag
    #print(lis, su, P)
    return True

def main():
    min_P = 1000000000
    left = 1
    right = 1000000000
    while  left < right-1:
        if (left + right) % 2 == 0:
            mid = (left + right)//2
        else:
            mid = (left + right)//2 + 1
        #print(left, mid, right, end=" ")
        if check(mid):
            right = mid
            if min_P > mid:
                min_P = mid
        else:
            left = mid
    
    #print(left,right)
    print(min_P)
if __name__ == '__main__':
    n, k = map(int, input().rstrip().split(" "))
    #n,k= 5,3
    baggage = [int(input()) for i in range(n)]
    #baggage = [8,1,7,3,9]
    
    main()

Submission status: Wrong Answer

Solution code:
def check(p):
    i = 0
    for _ in range(k):
        total = 0
        while total+n_list[i] <=p:
            total += n_list[i]
            i += 1
            if i == n:
                return n
    return i

def solve():
    left   = 0
    right  = 10**5 * 10**4
    middle = 0
    while left-right > 1:
        middle = (left+right)//2
        temp_ans = check(middle)
        if temp_ans >= n:
            right = middle
        else:
            left  = middle
    return right

n,k = map(int,input().split())
n_list = [int(input()) for _ in range(n)]
ans = solve()
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(lambda x: int(x), input().split())
    w = [int(input()) for _ in range(n)]
    while len(w) > k:
        index = max(1, w.index(min(w)))
        weight = w.pop(index)
        w[index-1] += weight
    print(max(w))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
buggage_num, track_num = map(int, input().split())
weights = [int(input()) for i in range(buggage_num)]

track_weights = [0 for i in range(track_num)]
for weight in reversed(sorted(weights)):
    # 荷物の積まれたトラックの中から、最も積載量が少ないトラックを取得する処理
    min_weight = track_weights[0]
    min_index = 0
    for i, track_weight in enumerate(track_weights):
        if track_weight < min_weight:
            min_weight = track_weight
            min_index = i
    track_weights[min_index] += weight
print(max(track_weights))

Submission status: Wrong Answer

Solution code:
import math
from typing import List

buggage_num, truck_num = map(int, input().split())
buggage_list = [int(input()) for i in range(buggage_num)]


def able_to_load_buggage(max_weight: int,
                         truck_num: int, buggage_list: List[int]) -> bool:
    i = 0
    truck = [0 for i in range(truck_num + 1)]
    for buggage in buggage_list:
        if truck[i] + buggage <= max_weight:
            truck[i] += buggage
        else:
            i += 1
            truck[i] += buggage
        if i > (truck_num - 1):
            return False
    if truck[truck_num - 1] > max_weight:
        return False
    else:
        return True


# data = [i for i in range(15)]
# for d in data:
#     result = able_to_load_buggage(d, truck_num, buggage_list)
#     print(f'{d} {result}')

left = 0
right = 100000 * 10000 + 1
i = 0
while left < right:
    i += 1
    mid = math.floor((left + right) / 2)
    result = able_to_load_buggage(mid, truck_num, buggage_list)
    # print(f'{i} {left} {mid} {right} {result}')
    if result:
        right = mid
    else:
        left = mid + 1
# print(f'{left} {mid} {right}')
print(left)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())

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

l.sort(reverse=True)
# print(l)

sum_list = [0] * k
for li in l:
    mn = min(sum_list)
    i = sum_list.index(mn)
    sum_list[i] += li
    # print(sum_list)

# print(l)
ans = max(sum_list)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())

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


p = l[0]
while True:
    sm_k = 0
    k_no = 1
    for li in l:
        sm_k += li
        if sm_k > p:
            k_no += 1
            sm_k = 0
    p += 1

    if k_no <= k:
        print(p)
        break

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())

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

p = l[0]
while True:
    sm_k = 0
    k_no = 1
    for li in l:
        sm_k += li
        if sm_k > p:
            k_no += 1
            sm_k = 0

    if k_no <= k:
        print(p)
        break

    p += 1

Submission status: Wrong Answer

Solution code:
# -*- coding utf 8 -*-
# Allocation
# 2019. 4/30

if __name__ == '__main__':
    A = []
    n, k = map(int, input().split())
    for i in range(n):
        A.append(int(input()))

    A.sort()
    A.reverse()
    weight = [0] * k
    for i in range(0, n):
        min_weight = weight.index(min(weight))
        weight[min_weight] += A[i]

    print(max(weight))

Submission status: Wrong Answer

Solution code:
n,k=map(int,raw_input().split())
w=[input() for _ in range(n)]
l=max(w)
r=sum(w)
while l+1<r:
    m=(l+r)/2
    s=c=0
    for i in w:
        s+=i
        if s>m:s=i;c+=1
    if c<k:r=m
    else:l=m+1
print l

Submission status: Wrong Answer

Solution code:
import math, sys

def loadable(w, n, k, p, wsum):
    wait = 0
    for i in range(n):
        wait += w[i]
        wsum -= w[i]
        if wait > p:
            k -= 1
            wait = w[i]
            if k == 0 or p < wsum / k:
                return False
    return True

n, k = map(int, sys.stdin.readline().split())
w = [int(sys.stdin.readline()) for _ in range(n)]

wsum = sum(w)

p = max(int(math.ceil(wsum / k)), max(w))
pre_f = p -1
pre_s = None

while True:
    if loadable(w, n, k, p, wsum):
        pre_s = p
    else:
        pre_f = p

    if pre_s != None and pre_s - pre_f == 1:
            break
    
    if pre_s:
        p = int((pre_s + pre_f) / 2)
    else:
        p = math.ceil(p * 1.01)
    
print(p)

Submission status: Wrong Answer

Solution code:
n, k = [ int( val ) for val in raw_input( ).split( " " ) ]
w = []
maxW = sumW = 0
for i in range( n ):
	num = int( raw_input( ) )
	sumW += num
	w.append( num )
	if maxW < num:
		maxW = num

minP = 0
if 1 == k:
	minP = sumW
elif n == k:
	minP = maxW
else:
	left = maxW
	right = 100000*10000
	while left <= right:
		middle = ( left+right )//2
		truckCnt = i = loadings = 0
		while i < n:
			loadings += w[i]
			if middle < loadings:
				truckCnt += 1
				if k < truckCnt+1:
					break
				loadings = w[i]
			i += 1

		if truckCnt+1 <= k:
			minP = middle
		
		if k < truckCnt+1:
			left = middle + 1
		else:
			right = middle - 1

Submission status: Wrong Answer

Solution code:
n,k=map(int,raw_input().split())
l=[0]*k
h=[]
a=n
while a:
    a-=1
    h.append(int(raw_input()))
h.sort()
b=0
while b>-n:
    b-=1
    print h[b]
    l[l.index(min(l))]+=h[b]
print l
print max(l)

Submission status: Wrong Answer

Solution code:
n,k=map(int,raw_input().split())
l=[0]*k
h=[]
a=n
while a:
    a-=1
    h.append(int(raw_input()))
h.sort()
b=0
while b>-n:
    b-=1
    l[l.index(min(l))]+=h[b]
print max(l)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
w = [int(input()) for i in range(n)]
l = max(w)
r = sum(w)

while l < r:
    m = (l + r) / 2
    stack = 0
    car = 0
    for i in w:
        stack += i
        if stack > m:
            stack = i
            car += 1
        if car < k:
            r = m
        else:
            l = m + 1
print(l)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
w = [int(input()) for i in range(n)]
l = max(w)
r = sum(w)

while l < r:
    m = (l + r) // 2
    stack = 0
    car = 0
    for i in w:
        stack += i
        if stack > m:
            stack = i
            car += 1
        if car < k:
            r = m
        else:
            l = m + 1
print(l)

Submission status: Wrong Answer

Solution code:
def need(A, p):
    count = 0
    track = 0
    for x in A:
        if count + x <= p:
            count += x
        else:
            track += 1
            count = x
    if count > 0:
        return track + 1
    else:
        return track

n, k = map(int, raw_input().split())
W = [int(raw_input()) for i in xrange(n)]

left = 1
right = sum(W)
while left < right:
    mid = (left + right) / 2
    track = need(W, mid)
    if k == track:
        while k == need(W, mid-1):
            mid -= 1
        print mid
        break
    elif k < track:
        right = mid
    else:
        left = mid + 1

Submission status: Wrong Answer

Solution code:
def need(A, p):
    if max(A) > p:
        return 100001
    count = 0
    track = 0
    for x in A:
        if count + x <= p:
            count += x
        else:
            track += 1
            count = x
    if count > 0:
        return track + 1
    else:
        return track

n, k = map(int, raw_input().split())
W = [int(raw_input()) for i in xrange(n)]

left = max(W)
right = sum(W)
while left < right:
    mid = (left + right) / 2
    track = need(W, mid)
    if k == track:
        while k == need(W, mid-1):
            mid -= 1
        print mid
        break
    elif k < track:
        right = mid
    else:
        left = mid + 1

Submission status: Wrong Answer

Solution code:
def need(A, p):
    if max(A) > p:
        return 100001
    count = 0
    track = 0
    for x in A:
        if count + x <= p:
            count += x
        else:
            track += 1
            count = x
    if count > 0:
        return track + 1
    else:
        return track

n, k = map(int, raw_input().split())
W = [int(raw_input()) for i in xrange(n)]

left = 1
right = sum(W)
while left < right:
    mid = (left + right) / 2
    track = need(W, mid)
    if k == track:
        while k == need(W, mid-1):
            mid -= 1
        print mid
        break
    elif k < track:
        right = mid
    else:
        left = mid + 1

Submission status: Wrong Answer

Solution code:
def need(A, p):
    if max(A) > p:
        return 100001
    count = 0
    track = 0
    for x in A:
        if count + x <= p:
            count += x
        else:
            track += 1
            count = x
    if count > 0:
        return track + 1
    else:
        return track

n, k = map(int, raw_input().split())
W = [int(raw_input()) for i in xrange(n)]

left = 1
right = sum(W) + 1
while left < right:
    mid = (left + right) / 2
    track = need(W, mid)
    if k == track:
        while k == need(W, mid-1):
            mid -= 1
        print mid
        break
    elif k > track:
        right = mid
    else:
        left = mid + 1

Submission status: Wrong Answer

Solution code:
def need(A, p):
    if max(A) > p:
        return 100001
    count = 0
    track = 0
    for x in A:
        if count + x <= p:
            count += x
        else:
            track += 1
            count = x
    if count > 0:
        return track + 1
    else:
        return track

n, k = map(int, raw_input().split())
W = [int(raw_input()) for i in xrange(n)]

left = 1
right = sum(W) + 1
while left < right:
    mid = (left + right) / 2
    track = need(W, mid)
    if k == track:
        while k == need(W, mid-1):
            mid -= 1
        print mid
        quit()
    elif k > track:
        right = mid
    else:
        left = mid + 1
if left == right:
    print mid

Submission status: Wrong Answer

Solution code:
#coding:utf-8
#1_4_D
import math

n, k = map(int, input().split())
weight = [int(input()) for i in range(n)]
print(math.ceil(sum(weight)/k))

Submission status: Wrong Answer

Solution code:
#coding:utf-8
#1_4_D
import math

n, k = map(int, input().split())
weight = [int(input()) for i in range(n)]
print(max(math.ceil(sum(weight)/k), max(weight)))

Submission status: Wrong Answer

Solution code:
#coding:utf-8
#1_4_D
import math

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

print(max(max(weight), math.ceil(sum(weight)/k)))

Submission status: Wrong Answer

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

from math import ceil

def check(p, k, T, n):
    i = 0
    for j in range(k):
        s = 0
        while s + T[i] <= p:
            s += T[i]
            i += 1
            if (i == n):
                return n
    return i

def solve(n, k, weights):
    left = 0
    right = 100000 * 10000 #荷物の個数 * 1個当たりの最大重量

    while (right - left >= 1):
        mid = (left + right) / 2
        v = check(mid, k, weights, n)
        if v >= n:
            right = mid
        else:
            left = mid
    return mid

n, k = list(map(int, input().split()))
weights = [int(input()) for i in range(n)]
ans = solve(n, k, weights)
print (int(ans))

Submission status: Wrong Answer

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

from math import ceil

def check(p, k, T, n):
    i = 0
    for j in range(k):
        s = 0
        while s + T[i] <= p:
            s += T[i]
            i += 1
            if (i == n):
                return n
    return i

def solve(n, k, weights):
    left = 0
    right = sum(weights) #荷物の個数 * 1個当たりの最大重量

    while (right - left > 1):
        mid = (left + right) / 2
        v = check(mid, k, weights, n)
        if v == n:
            right = mid
        else:
            left = mid
    return mid

n, k = list(map(int, input().split()))
weights = [int(input()) for i in range(n)]
ans = solve(n, k, weights)
print (ceil(ans))

Submission status: Wrong Answer

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

from math import ceil

def check(p, k, T, n):
    i = 0
    for j in range(k):
        s = 0
        while s + T[i] <= p:
            s += T[i]
            i += 1
            if (i == n):
                return n
    return i

def solve(n, k, weights):
    left = 0
    right = sum(weights)

    while (right - left > 1):
        mid = ceil((left + right) / 2)
        v = check(mid, k, weights, n)
        if v == n:
            right = mid
        else:
            left = mid
        print (left, mid, right)
    return mid

n, k = list(map(int, input().split()))
weights = [int(input()) for i in range(n)]
ans = solve(n, k, weights)
print (ans)

Submission status: Wrong Answer

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

from math import ceil

def check(p, k, T, n):
    i = 0
    for j in range(k):
        s = 0
        while s + T[i] <= p:
            s += T[i]
            i += 1
            if (i == n):
                return n
    return i

def solve(n, k, weights):
    left = 0
    right = sum(weights) #荷物の個数 * 1個当たりの最大重量

    while (right - left > 1):
        mid = ceil((left + right) / 2)
        v = check(mid, k, weights, n)
        if v == n:
            right = mid
        else:
            left = mid
    return mid

n, k = list(map(int, input().split()))
weights = [int(input()) for i in range(n)]
ans = solve(n, k, weights)
print (ans)

Submission status: Wrong Answer

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

from math import ceil


#最大積載量pのk台のトラックで何個の荷物を積めるか
def check(p, k, T, n):
    i = 0
    for j in range(k):
        s = 0
        while s + T[i] <= p:
            s += T[i]
            i += 1
            if (i == n):
                return n
    # 積みきれなかったとき
    return i

def solve(n, k, weights):
    left = 0
    right = sum(weights)
    #　二分法を用いて最小のpすなわちcheckを満たすpを求める
    while (right - left > 1):
        mid = ceil((left + right) / 2)
        v = check(mid, k, weights, n)
        if v == n:
            right = mid
        else:
            left = mid
        print (left, mid, right)
    return mid

n, k = list(map(int, input().split()))
weights = [int(input()) for i in range(n)]
ans = solve(n, k, weights)
print (ans)

Submission status: Wrong Answer

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

from math import ceil


#最大積載量pのk台のトラックで何個の荷物を積めるか
def check(p, k, T, n):
    i = 0
    for j in range(k):
        s = 0
        while s + T[i] <= p:
            s += T[i]
            i += 1
            if (i == n):
                return n
    # 積みきれなかったとき
    return i

def solve(n, k, weights):
    left = 0
    right = sum(weights)
    #　二分法を用いて最小のpすなわちcheckを満たすpを求める
    while (right - left > 1):
        mid = ceil((left + right) / 2)
        v = check(mid, k, weights, n)
        if v == n:
            right = mid
        else:
            left = mid
    return mid

n, k = list(map(int, input().split()))
weights = [int(input()) for i in range(n)]
ans = solve(n, k, weights)
print (ans)

Submission status: Wrong Answer

Solution code:
def carriable_baggage(baggage, baggage_num, truck_capacity, truck_num):
    """Return the number of baggae which trucks can carry."""
    laden_baggage = 0
    for i in range(truck_num):
        laden_weight = 0
        while laden_weight + baggage[laden_baggage] <= truck_capacity:
            laden_weight += baggage[laden_baggage]
            laden_baggage += 1
            if laden_baggage == baggage_num:
                return baggage_num
    return laden_baggage

def min_capacity(baggage, baggage_num, truck_num):
    """Return the minimum value of maximum load capacity of trucks."""
    heaviest_baggage = max(baggage)
    average_capacity = sum(baggage) // truck_num
    left = max(heaviest_baggage, average_capacity)
    right = heaviest_baggage * baggage_num
    while right - left > 1:
        mid = (left + right) // 2
        v = carriable_baggage(baggage, baggage_num, mid, truck_num)
        if v >= baggage_num:
            right = mid;
        else:
            left = mid
    return right


import sys

n, k = map(int, sys.stdin.readline().split())

T = list(map(int, sys.stdin))

P = min_capacity(T, n, k)

print(P)

Submission status: Wrong Answer

Solution code:
def carriable_baggage(baggage, baggage_num, truck_capacity, truck_num):
    """Return the number of baggae which trucks can carry."""
    laden_baggage = 0
    for i in range(truck_num):
        laden_weight = 0
        while laden_weight + baggage[laden_baggage] <= truck_capacity:
            laden_weight += baggage[laden_baggage]
            laden_baggage += 1
            if laden_baggage == baggage_num:
                return baggage_num
    return laden_baggage

def min_capacity(baggage, baggage_num, truck_num):
    """Return the minimum value of maximum load capacity of trucks."""
    left = max(baggage)
    right = sum(baggage)
    while right - left > 1:
        mid = (left + right) // 2
        v = carriable_baggage(baggage, baggage_num, mid, truck_num)
        if v >= baggage_num:
            right = mid;
        else:
            left = mid
    return right


import sys

n, k = map(int, sys.stdin.readline().split())

T = list(map(int, sys.stdin))

P = min_capacity(T, n, k)

print(P)

Submission status: Wrong Answer

Solution code:
def carriable_baggage(baggage, baggage_num, truck_capacity, truck_num):
    """Return the number of baggae which trucks can carry."""
    laden_baggage = 0
    for i in range(truck_num):
        laden_weight = 0
        while laden_weight + baggage[laden_baggage] <= truck_capacity:
            laden_weight += baggage[laden_baggage]
            laden_baggage += 1
            if laden_baggage == baggage_num:
                return baggage_num
    return laden_baggage

def min_capacity(baggage, baggage_num, truck_num):
    """Return the minimum value of maximum load capacity of trucks."""
    left = 0
    right = 1000000000
    while right - left > 1:
        mid = (left + right) // 2
        print("mid is {0}".format(mid))
        v = carriable_baggage(baggage, baggage_num, mid, truck_num)
        if v >= baggage_num:
            right = mid;
        else:
            left = mid
    return right


import sys

n, k = map(int, sys.stdin.readline().split())

T = list(map(int, sys.stdin))

P = min_capacity(T, n, k)

print(P)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
#1_4_D
def is_carriable(w_lim, trucks, loads):
    """ Check whether w_lim(maximum carrying capacity) is possible or not """
    i = 0
    while trucks > 0:
        w = 0
        while i < len(loads):
            if w + loads[i] > w_lim:
                trucks -= 1
                break
            w += loads[i]
            i += 1
        if i == len(loads):
            return True
    return False

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

left = max(loads)
right = sum(loads) + 1

while right - left > 1:
    mid = (left + right) // 2
    print("left = {}, mid = {}, right = {}".format(left, mid, right))
    if is_carriable(mid, trucks, loads):
        ans = mid
        right = mid
    else:
        left = mid

if is_carriable(max(loads), trucks, loads):
    ans = max(loads)

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil


def check_p(p):
    global k, ws
    ct, nt = 0, 1
    for w in ws:
        if ct + w <= p:
            ct += w
        else:
            nt += 1
            if nt > k:
                return False
            ct = w
    return True


n, k = map(int, input().split())

ws = [int(input()) for _ in range(n)]

p = ceil(sum(ws) / k)

while True:
    if check_p(p):
        break
    p += 1

print(p)

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
T = []

for i in range(n):
  T.append(input())

left = 0
right = 100000*10000
while right-left>1:
  mid = (right + left)/2

  j = 0
  s = 0
  while s + T[j] <= mid:
    s += T[j]
    j += 1
    if j == n:
      break

  if j>=n:
    right = mid
  else:
    left = mid

print right

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
T = []

for i in range(n):
  T.append(input())

left = 0
right = 100000*10000
while right-left>1:
  mid = (right + left)/2

  j = 0
  for x in range(k):
    s = 0


  if j>=n:
    right = mid
  else:
    left = mid

print right

Submission status: Wrong Answer

Solution code:
# coding:utf-8
n, k = map(int,raw_input().split())
ws = []
for _ in xrange(n):
  ws.append(int(raw_input()))
ws.sort()
ws.reverse()
ps = [0] * k
for w in ws:
  min_p = ps.index(min(ps))
  ps[min_p] += w
print max(ps)

Submission status: Wrong Answer

Solution code:
import sys

def allocate(k, w):
    t = [0] * k
    for wi in w:
        t[0] += wi
        insertionSort(t, k)
    return t[k - 1]

def qsort(li):
    if len(li) < 2:
        return li

    pivot = li[0]
    li_rest =  li[1:]
    smaller = [x for x in li_rest if x < pivot]
    larger = [x for x in li_rest if x >= pivot]

    return  qsort(larger) + [pivot] + qsort(smaller)

def insertionSort(A, N):
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v

if __name__ == "__main__":
    w = sys.stdin.readlines()
    k = int(w[0].split()[1])
    del w[0]
    w = [int(wi) for wi in w]
    print allocate(k, qsort(w))

Submission status: Wrong Answer

Solution code:
import sys
import math

def allocate(k, w):
    t = [0] * k
    avg = math.ceil(1.0 * sum(w) / k)
    print avg, sum(w), k, sum(w) / k
    print w
    while True:
        maxp = p = i = 0
        for wi in w:
            p += wi
            if p > avg:
                p -= wi
                if p > maxp:
                    maxp = p
                p = wi
                i += 1
        if i < k and maxp <= avg:
            return maxp
        avg += 1

if __name__ == "__main__":
    w = sys.stdin.readlines()
    k = int(w[0].split()[1])
    del w[0]
    w = [int(wi) for wi in w]
    print allocate(k, w)

Submission status: Wrong Answer

Solution code:
import sys
import math

def allocate(k, w):
    t = [0] * k
    avg = math.ceil(1.0 * sum(w) / k)
    while True:
        maxp = p = i = 0
        for wi in w:
            p += wi
            if p > avg:
                p -= wi
                if p > maxp:
                    maxp = p
                p = wi
                i += 1
        if i < k and maxp <= avg:
            return maxp
        avg += 1

if __name__ == "__main__":
    w = sys.stdin.readlines()
    k = int(w[0].split()[1])
    del w[0]
    w = [int(wi) for wi in w]
    print allocate(k, w)