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:
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):
            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)
print(maxinp)

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):
            print(maxP)
            break

Submission status: Wrong Answer

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

def can(p_org,k):
	p = p_org
	for ww in w:
		if ww < p:
			p -= ww
		else:
			p = p_org
			k -= 1
		if not(k):
			return False
	return True


left,right = 0,sum(w)+1
while left+1 < right:
	middle = (left+right) // 2
	if can(middle,k):
		right = middle
	else:
		left = middle
print(right)

Submission status: Wrong Answer

Solution code:
n,k = [int(s) for s in input().split()]
#n,k = [int(s) for s in data.pop().split()]
w = []
[w.append(int(input())) for i in range(n)]
#[w.append(int(data.pop())) for i in range(n)]

def can(p_org,k):
	p = p_org
	for ww in w:
		if ww <= p:
			p -= ww
		else:
			p = p_org
			k -= 1
		if not(k):
			return False
	return True


left,right = 0,sum(w)+1
while left+1 < right:
	middle = (left+right) // 2
	if can(middle,k):
		right = middle
	else:
		left = middle
print(right)

Submission status: Wrong Answer

Solution code:
n,k = [int(s) for s in input().split()]
#n,k = [int(s) for s in data.pop().split()]
w = []
[w.append(int(input())) for i in range(n)]
#[w.append(int(data.pop())) for i in range(n)]

def can(p_org,k):
	p = p_org
	for ww in w:
		if ww <= p:
			p -= ww
		else:
			p = p_org - ww
			k -= 1
		if not(k):
			return False
	return True


left,right = 0,sum(w)+1
while left+1 < right:
	middle = (left+right) // 2
	if can(middle,k):
		right = middle
	else:
		left = middle
print(right)

Submission status: Wrong Answer

Solution code:
n,k = [int(s) for s in input().split()]
#n,k = [int(s) for s in data.pop().split()]
w_org = []
[w_org.append(int(input())) for i in range(n)]
#[w_org.append(int(data.pop())) for i in range(n)]

def can(p_org,k):
	p = p_org
	w = w_org[:]
	while k and w:
		ww = w[0]
		if ww <= p:
			p -= ww
			w.pop(0)
		else:
			p = p_org
			k -= 1
		if p == 0:
			p = p_org
			k -= 1
		print(ww,k,p)
	return not(w)


left,right = 0,sum(w_org)+1
while left+1 < right:
	middle = (left+right) // 2
	if can(middle,k):
		right = middle
	else:
		left = middle
print(right)

Submission status: Wrong Answer

Solution code:
n,k = [int(x) for x in input().split()]

w = []

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

w.sort(reverse = True)

def f(p, k, w):
	cnt = 0
	sumw = [0 for x in range(k)]
	
	for i in w:
		mini = sumw.index(min(sumw))
		sumw[mini] += i
		
		if sumw[mini] > p:
			break
		else:
			cnt += 1
	
	return cnt
	
pmin = 0
pmax = sum(w)

while pmin < pmax:
	tmpp = (pmin + pmax) // 2
	tmp = f(tmpp, k , w)
	
	if tmp < n:
		pmin = tmpp + 1
	else:
		pmax = tmpp

print(pmax)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Allocation

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

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

"""
import sys

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

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

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

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

    print(P)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Allocation

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

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

"""
import sys

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

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

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

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

    print(P)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def can_cant(n,k,w_n,p):
    w_p=[]
    wp=0
    for w in w_n:
        if w>p:
            return False
        elif wp+w<p:
            wp+=w
        elif wp+w==p:
            wp+=w
            w_p.append(wp)
            wp=0
        elif wp+w>p:
            w_p.append(wp)
            wp=w
        #else:
            #if wp!=0:
               # w_p.append(wp)
              #  wp=0
          #   else:wp=w

    if wp<p:
        w_p.append(wp)


    if len(w_p)<=k:
        #print("True")
        return True
    elif len(w_p)>k:
        #print("False")
        return False

if __name__=="__main__":

    n,k=list(map(int,input("??????????????°??¨????????°??°?????\?????????:",).split()))

    w_n=[int(input("????????????????????\?????????:",)) for i in range(n)]

    #print(can_cant(n,k,w_n,10))

    min_p = sum(w_n) // k
    max_p = sum(w_n)
    p = (min_p + max_p) // 2
    #print("min_p={},max_p={},p={}".format(min_p, max_p, p))
    pre_p=0

    while min_p < p :
        print(p)
        result=can_cant(n, k, w_n, p)
        if result :
            pre_p=p
            max_p = p
            p = (min_p + max_p) // 2
            #print("max_p=p={},min_p={}, p={}".format(max_p, min_p, p))
        elif not result:
            pre_p = p
            min_p = p
            p = (min_p + max_p) // 2
            #print("max_p={},min_p=p={}, p={}".format(max_p, min_p, p))
    print(pre_p)

Submission status: Wrong Answer

Solution code:
def can_cant(n,k,w_n,p):
    w_p=[]
    wp=0
    for w in w_n:
        if w>p:
            return False
        elif wp+w<p:
            wp+=w
        elif wp+w==p:
            wp+=w
            w_p.append(wp)
            wp=0
        elif wp+w>p:
            w_p.append(wp)
            wp=w

    if wp<p:
        w_p.append(wp)

    if len(w_p)<=k:
        return True
    elif len(w_p)>k:
        return False

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

w_n=[int(input()) for i in range(n)]


min_p = sum(w_n) // k
max_p = sum(w_n)
p = (min_p + max_p) // 2
pre_p=0

while min_p < p :
    result=can_cant(n, k, w_n, p)
    if result :
        pre_p=p
        max_p = p
        p = (min_p + max_p) // 2
    elif not result:
        pre_p = p
        min_p = p
        p = (min_p + max_p) // 2
print(pre_p)

Submission status: Wrong Answer

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

def f(P):
    mx = k * P
    total = 0
    for i in range(n):
        total += w[i]
        if total > mx:
            return i - 1
    return n

P = 0
while f(P) < n:
    P += 1
print(P)

Submission status: Wrong Answer

Solution code:
n, k = map(int, raw_input().split())
a = []
for i in range(n):
    a.append(int(raw_input()))

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

max_weight = max(a) * k
left = 0
right = max_weight
ans = 0
while left < right:
    mid = int((left + right) / 2)
    if calcNum(mid) >= n:
        right = mid
    elif calcNum(mid) < n:
        left = mid + 1
print right

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
lag = []
for l in range(n):
    lag.append(int(input()))
w_max = 100000*1000000
w_min = 1
while w_min < w_max:
    w_mid = (w_max + w_min) // 2
    tracks = 0
    current = 0
    for i in range(n):
        if lag[i] > w_mid:
            tracks = k
            break
        elif lag[i] + current > w_mid:
            tracks += 1
            current = lag[i]
        else:
            current += lag[i]
    if tracks < k:
        w_max = w_mid
    else:
        w_min += w_mid + 1
print(w_max)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
lag = []
for l in range(n):
    lag.append(int(input()))
w_max = 100000*100000
w_min = 0
while w_min < w_max:
    w_mid = (w_max + w_min) // 2
    tracks = 0
    current = 0
    for i in range(n):
        if lag[i] > w_mid:
            tracks = k
            break
        elif lag[i] + current > w_mid:
            tracks += 1
            current = lag[i]
        else:
            current += lag[i]
    if tracks < k:
        w_max = w_mid-1
    else:
        w_min += w_mid + 1
print(w_max)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
lag = []
for l in range(n):
    lag.append(int(input()))
w_max = 100000*100000
w_min = 0
while w_min < w_max:
    w_mid = (w_max + w_min) // 2
    tracks = 0
    current = 0
    for i in range(n):
        if lag[i] > w_mid:
            tracks = k
            break
        elif lag[i] + current > w_mid:
            tracks += 1
            current = lag[i]
        else:
            current += lag[i]
    if tracks < k:
        w_max = w_mid
    else:
        w_min += w_mid + 1
print(w_max)

Submission status: Wrong Answer

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

def check(P):
    s, cnt = 0, 1
    for i in range(n):
        if s + w[i] <= P:
            s += w[i]
        else:
            s = w[i]
            cnt += 1
    return cnt <= k

l, r = 0, 10000 * n
while r - l > 1:
    m = (l + r) // 2
    if check(m):
        r = m
    else:
        l = m

print(r)

Submission status: Wrong Answer

Solution code:


def p(k,w,maxP):
    count = 1
    tmpList = []
    mP = 0
    for x in w:
        if sum(tmpList)+x <= maxP:
            tmpList.append(x)
            mP = max(sum(tmpList),mP)
        else:
            count += 1
            tmpList = []
            tmpList.append(x)
    if count > k:
        result = False
    else:
        result = True

    return result, count, mP

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


w = []

for _ in range(n):
    w.append((int)(input()))
rangeMax = 1000000000
rangeMin = 1

while _:
    rangeMid = (rangeMax + rangeMin)//2
    if p(k,w,rangeMid)[0] == False and p(k,w,rangeMid+1)[0] == False:
        rangeMin = rangeMid
    elif p(k,w,rangeMid)[0] == True and p(k,w,rangeMid+1)[0] == True:
        rangeMax = rangeMid
    else:
        break

print(p(k,w,rangeMid+1)[2])

Submission status: Wrong Answer

Solution code:


def p(k,w,maxP):
    count = 1
    tmpList = []
    mP = 0
    for x in w:
        if sum(tmpList)+x <= maxP:
            tmpList.append(x)
            mP = max(sum(tmpList),mP)
        else:
            count += 1
            tmpList = []
            tmpList.append(x)
    mP = max(sum(tmpList),mP)
    
    if count > k:
        result = False
    else:
        result = True

    return result, count, mP

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


w = []

for _ in range(n):
    w.append((int)(input()))
rangeMax = 1000000000
rangeMin = 1

while _:
    rangeMid = (rangeMax + rangeMin)//2
    if p(k,w,rangeMid)[0] == False and p(k,w,rangeMid+1)[0] == False:
        rangeMin = rangeMid
    elif p(k,w,rangeMid)[0] == True and p(k,w,rangeMid+1)[0] == True:
        rangeMax = rangeMid
    else:
        break

print(p(k,w,rangeMid+1)[2])

Submission status: Wrong Answer

Solution code:


def p(k,w,maxP):
    count = 1
    tmpList = []
    mP = 0
    for x in w:
        if sum(tmpList)+x <= maxP:
            tmpList.append(x)
            mP = max(sum(tmpList),mP)
        else:
            count += 1
            tmpList = []
            tmpList.append(x)
            mP = max(sum(tmpList),mP)
    
    if count > k :
        result = False
    else:
        result = True

    return result, count, mP

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


w = []

for _ in range(n):
    w.append((int)(input()))
rangeMax = 1000000000
rangeMin = 1

while _:
    rangeMid = (rangeMax + rangeMin)//2
    print(p(k,w,rangeMid))
    print(p(k,w,rangeMid+1))
    print("---")

    if p(k,w,rangeMid)[0] == False and p(k,w,rangeMid+1)[0] == False:
        rangeMin = rangeMid
    elif p(k,w,rangeMid)[0] == True and p(k,w,rangeMid+1)[0] == True:
        rangeMax = rangeMid
    else:
        break

print(p(k,w,rangeMid+1)[2])

Submission status: Wrong Answer

Solution code:
import copy
n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]
w.sort(reverse=True)
Ps = [w[i] for i in range(k)]
if n>k:
    for i in range(k, n):
        min_ind = Ps.index(min(Ps))
        Ps[min_ind] += w[i]
print(max(Ps))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]
w.sort(reverse=True)
if k<=n:
    Ps = [w[i] for i in range(k)]
    if n>k:
        for i in range(k, n):
            min_ind = Ps.index(min(Ps))
            Ps[min_ind] += w[i]
else:
    Ps = [w[i] for i in range(n)]
print(max(Ps))

Submission status: Wrong Answer

Solution code:

line = input().split()
n = int(line[0])
k = int(line[1])
ws = []

def cal(p):
    counter = 0
    tra = 0
    num = 0
    for i in ws:
        if i + tra <= p:
            tra += i
        else:
            counter += 1
            if counter > k:
                break
            tra = i
        num += 1
    return num

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

left = max(max(ws),int(sum(ws)/k))
right = max(ws)*n

while True:
    mid = int((left + right) / 2)
    if cal(mid) >= n:
        right = mid
    else:
        left = mid + 1
    if left == right:
        print(left)
        break

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
w = [int(input()) for i in range(n)]
p_min = max(w)-1
p_max = sum(w)+1

while p_max - p_min > 1:
    p_mid = int(p_min + (p_max - p_min)/2)
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p_mid:
            w_tmp = w_i
            k_tmp += 1
    
    if k_tmp <= k:
        p_max = p_mid
    else:
        p_min = p_mid

print(p_mid)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
w = [int(input()) for i in range(n)]
p_min = max(w)-1
p_max = sum(w)+1

while p_min < p_max:
    p_mid = int(p_min + (p_max - p_min)//2)
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p_mid:
            w_tmp = w_i
            k_tmp += 1
    
    if k_tmp <= k:
        p_max = p_mid
    else:
        p_min = p_mid + 1

print(p_mid)

Submission status: Wrong Answer

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

while p_min < p_max:
    p_mid = int(p_min + (p_max - p_min)//2)
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p_mid:
            w_tmp = w_i
            k_tmp += 1
    
    if k_tmp > k:
        p_min = p_mid + 1
    else:
        p_max = p_mid

print(p_mid)

Submission status: Wrong Answer

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

while p_min < p_max:
    p_mid = int(p_min + (p_max - p_min)//2)
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p_mid:
            w_tmp = w_i
            k_tmp += 1
    
    if k_tmp > k:
        p_min = p_mid + 1
    else:
        p_max = p_mid - 1

print(p_mid)

Submission status: Wrong Answer

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

def binarySearch(left,right):
    mid = int(left + (right - left)//2)
    while right - left > 1:
        if check(mid,w,k):
            right = mid
            mid = int(left + (right - left)//2)
        else:
            left = mid
            mid = int(left + (right - left)//2)
    return left

def check(p,w,k):
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p:
            w_tmp = w_i
            k_tmp += 1
            if k_tmp > k:
                return False
    return True

print(binarySearch(max(w),sum(w)))

Submission status: Wrong Answer

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

def binarySearch(left,right):
    mid = int(left + (right - left)//2)
    while right - left > 1:
        if check(mid,w,k):
            right = mid
            mid = int(left + (right - left)//2)
        else:
            left = mid
            mid = int(left + (right - left)//2)
    return mid

def check(p,w,k):
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p:
            w_tmp = w_i
            k_tmp += 1
            if k_tmp > k:
                return False
    return True

print(binarySearch(max(w),sum(w)))

Submission status: Wrong Answer

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

def binarySearch(left,right):
    mid = 0
    while right - left > 1:
        mid = int(left + (right - left)//2)
        if check(mid,w,k):
            right = mid
        else:
            left = mid
    return mid

def check(p,w,k):
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p:
            w_tmp = w_i
            k_tmp += 1
            if k_tmp > k:
                return False
    return True

print(binarySearch(max(w),sum(w)))

Submission status: Wrong Answer

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

def binarySearch(left,right):
    mid = 0
    while right - left > 1:
        mid = int(left + (right - left)//2)
        if check(mid,w,k):
            right = mid
        else:
            left = mid + 1
    return left

def check(p,w,k):
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p:
            w_tmp = w_i
            k_tmp += 1
            if k_tmp > k:
                return False
    return True

print(binarySearch(max(w),sum(w)))

Submission status: Wrong Answer

Solution code:
n,k = map(int,raw_input().split())
sum = 0
for i in range(n):
    w = int(input())
    sum += w
if sum % k != 0:
    print sum/k+1
else:
    print sum/k

Submission status: Wrong Answer

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


def allcation(n, baggage):
    truck = [0] * n
    for weight in sorted(baggage, reverse=True):
        truck[min_index(truck)] += weight
    return max(truck)


def min_index(lst):
    index = 0
    mini = float("inf")
    for i, val in enumerate(lst):
        if val < mini:
            index = i
            mini = val
    return index


if __name__ == "__main__":
    n = [int(val) for val in input().split()]
    lst = [int(val) for val in sys.stdin.read().splitlines()]
    print(allcation(n[1], lst))

Submission status: Wrong Answer

Solution code:

nk=input().split()

n=int(nk[0])
k=int(nk[1])

weight=[int(input()) for i in range(n)]

def ok(m):
    load=0
    track=1
    # sum all the weight and count the track number we need
    for i in range(n):
        load+=weight[i]
        if load>m:
            load=0
            track+=1
            i-=1
            print(track)
        elif load==m:
            load=0
            track+=1
            print(track)
        else:
            print(track)
            continue

    if track<=k:
        return True
    else:
        return False

low=0
high=sum(weight)
while low+1<high:
# low<mid<high
#not ok(l) and ok(h)
    mid=(low+high)//2
    if ok(mid):
        high=mid
        print("high="+str(high))
    else:
        low=mid
        print("low="+str(low))

print(high)

Submission status: Wrong Answer

Solution code:



nk=input().split()

n=int(nk[0])
k=int(nk[1])

weight=[int(input()) for i in range(n)]

def ok(m):
    load=0
    track=1
    # sum all the weight and count the track number we need
    for i in range(n):
        load+=weight[i]
        if load>m:
            load=0
            track+=1
            i-=1
        elif load==m:
            load=0
            track+=1
        else:
            continue

    if track<=k:
        return True
    else:
        return False

low=0
high=sum(weight)
while low+1<high:
# low<mid<high
#not ok(l) and ok(h)
    mid=(low+high)//2
    if ok(mid):
        high=mid
    else:
        low=mid
print(high)

Submission status: Wrong Answer

Solution code:



nk=input().split()

n=int(nk[0])
k=int(nk[1])

weight=[int(input()) for i in range(n)]

def ok(m):
    load=0
    track=1
    # sum all the weight and count the track number we need
    for i in range(0,n,1):
        load+=weight[i]
        if load>m:
            load=weight[i]
            track+=1
        elif load==m:
            load=0
            track+=1
        else:
            continue

    if track<=k:
        return True
    else:
        return False

low=0
high=sum(weight)
while low+1<high:
# low<mid<high
#not ok(l) and ok(h)
    mid=(low+high)//2
    if ok(mid):
        high=mid
    else:
        low=mid
print(high)

Submission status: Wrong Answer

Solution code:



nk=input().split()

n=int(nk[0])
k=int(nk[1])

weight=[int(input()) for i in range(n)]

def ok(m):
    load=0
    track=1
    # sum all the weight and count the track number we need
    for i in range(n):
        load+=weight[i]
        if load==m:
            load=0
            if i!=n-1:
                track+=1
        elif load>m:
            load=weight[i]
            track+=1
        else:
            continue

    if track<=k:
        return True
    else:
        return False

low=0
high=sum(weight)
while low+1<high:
# low<mid<high
#not ok(l) and ok(h)
    mid=(low+high)//2
    if ok(mid):
        high=mid
    else:
        low=mid


print(high)

Submission status: Wrong Answer

Solution code:
import math

n, k = map(int, raw_input().split())
w = []
max = 0
sum = 0
for i in xrange(n):
	w_i = int(raw_input())
	if w_i > max:
		max = w_i
	sum += w_i
	w.append(w_i)

ave = math.ceil(sum*1.0/k)

if ave < max:
	print max
else:
	print ave

Submission status: Wrong Answer

Solution code:
import math

n, k = map(int, raw_input().split())
w = []
max = 0
sum = 0
for i in xrange(n):
	w_i = int(raw_input())
	if w_i > max:
		max = w_i
	sum += w_i
	w.append(w_i)

ave = int(math.ceil(sum*1.0/k))

if ave < max:
	print max
else:
	print ave

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop
n, k = map(int, readline().split())
hp = [0] * k
W = sorted((int(readline()) for _ in range(n)), reverse=True)
for w in W:
    a = heappop(hp)
    heappush(hp, a + w)
print(max(hp))

Submission status: Wrong Answer

Solution code:
import sys
from heapq import heapify, heappush, heappop
n, k = map(int, input().split())
hp = [0] * k
for w in sys.stdin:
    a = heappop(hp)
    heappush(hp, a + int(w))
print(max(hp))

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
n, k = map(int, input().split())
v = {int(readline()) for _ in range(n)}
lo = max(v) - 1
hi = int(1e10)
while hi - lo > 1:
    p = P = (lo + hi) // 2
    m = 1
    for i in v:
        if i > p:
            p = P
            m += 1
        p -= i
    if m <= k:
        hi = P
    else:
        lo = P
print(hi)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
N, K = map(int, input().split())
W = set(map(int, sys.stdin.read().splitlines()))
ma = max(W)
def check(x):
    if x < ma:
        return False
    use = 1
    rest = x
    for w in W:
        if rest >= w:
            rest -= w
        else:
            rest = x - w
            use += 1
    return use <= K
l = 0
r = sum(W)
while r - l > 1:
    m = (r + l) // 2
    if check(m):
        r = m
    else:
        l = m
print(r)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
N, K = map(int, input().split())
W = tuple(map(int, sys.stdin.read().splitlines()))
ma = max(W)
def check(x):
    if x < ma:
        return False
    use = 1
    rest = x
    for w in W:
        if rest >= w:
            rest -= w
        else:
            rest = x - w
            use += 1
    return use <= K
l = max(W)
r = sum(W)
while r - l > 1:
    m = (r + l) // 2
    if check(m):
        r = m
    else:
        l = m
print(r)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
N, K = map(int, input().split())
W = sorted((map(int, sys.stdin.readlines())), reverse=True)
ma = max(W)
def check(x):
    if x < ma:
        return False
    use = 1
    rest = x
    for w in W:
        if rest >= w:
            rest -= w
        else:
            rest = x - w
            use += 1
            if use > K:
                return False
    return True
l = 0
r = sum(W)
while r - l > 1:
    m = (r + l) // 2
    if check(m):
        r = m
    else:
        l = m
print(r)

Submission status: Wrong Answer

Solution code:
num, track = [int(x) for x in input().split()]
hoge = 0
for _ in range(num):
    hoge += int(input())
print (hoge // track + 1)