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: Accepted

Solution code:
def check(t, n, k, p):
    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

if __name__ == "__main__":
    n, k = [int (x) for x in input().split()]
    t = []
    for i in range(n):
        t.append(int(input()))

    start, end = 0, 10000 * 100000

    while (end - start > 1):
        mid = (start + end) // 2
        v = check(t, n, k, mid)
        if v >= n:
            end = mid
        else:
            start = mid

    print(end)

Submission status: Accepted

Solution code:
def judge(loads,truck,truck_weight):#loadsは荷物のリスト.truckは使えるトラックの台数
    truck_num=1
    weight_sum=0
    for load in loads:
        if(weight_sum + load >truck_weight):
            truck_num+=1
            if(truck < truck_num):
                return 0
            weight_sum=load
        else:
            weight_sum+=load
    return 1

#与えられた条件で荷物の積み込みが可能なら１、不可能なら０を返す


def binal_search(loads,truck,min,max):#minからmaxの範囲で最小トラック積載量を求める
    if(max ==min):
        return  min
    mid=(min+max)//2
    if(judge(loads,truck,mid)):
        return binal_search(loads,truck,min,mid)
    else:
        return binal_search(loads,truck,mid+1,max)


        


n,truck=map(int,input().split())
loads=[]
for loop in range(n):
    loads.append(int(input()))
loads_max=sum(loads)
loads_min=max(loads)
print(binal_search(loads,truck,loads_min,loads_max))

Submission status: Accepted

Solution code:
import math

def p(ws, k, pmin, pmax):
    if pmax - pmin <= 1:
        return pmax

    mid = pmin + math.ceil((pmax - pmin)/2)
    ts = []

    t = 0
    for w in ws:
        if mid < t+w:
            ts.append(t)
            t = 0

        t += w

    if t > 0:
        ts.append(t)

    if len(ts) <= k:
        return p(ws, k, pmin, mid)
    else:
        return p(ws, k, mid, pmax)

def main():
    n, k = [int(x) for x in input().split(' ')]

    pmin = 0
    sumW = 0
    ws = []

    for _ in range(n):
        w = int(input())
        ws.append(w)

        pmin = max(pmin, w)
        sumW += w

    print(p(ws, k, pmin-1, sumW))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
n, k = map(int, sys.stdin.readline().split())

w = [int(sys.stdin.readline()) for _ in range(n)]
head = 0
tail = sum(w)
while head<tail-1:
    P = (head+tail)//2
    ld = 0 
    m = 1
    for u in w: 
        ld += u
        if ld>P: 
            m+=1 
            if k<m:    break 
            if u>P: break 
            ld = u
    else:
        tail=P
        continue
    head=P
    
print(tail)

Submission status: Accepted

Solution code:
'''
最大値 : n - k
最小値 : 1
8 1 7 3 9
興味あるのは最大値だけ。
'''

class Allocator(object):

    def __init__(self):
        self.N, self.K = map(int, input().split())
        self.ws = []

        for _ in range(self.N):
            self.ws.append(int(input()))

    def check(self, max_p):
        track, now = 0, 0
        for w in self.ws:
            if w > max_p:
                # wの値がmax_pを超えていた場合は、想定max値が小さすぎるのでFalse
                return False
            elif w + now > max_p:
                # nowの値にwを加えてmax_pを超えた場合は、それ以前までの値までしか積載出来なので、次のトラックを用意する。
                now = w
                track += 1
            else:
                # トラックに積荷をする。
                now += w

        if now > 0:
            # 全ての積荷を行ったのちにまだnowに残っていれば、trackを一つ用意する。
            track += 1

        if int(self.K) < track :
            return False

        return True


amin, amax = 0, int(10E10)
allocate = Allocator()

while amin + 1 != amax:
    amid = (amin + amax) // 2
    if allocate.check(amid):
        amax = amid
    else:
        amin = amid

print(amax)

Submission status: Accepted

Solution code:
import sys

# Set max recursion limit
sys.setrecursionlimit(1000000)


def li_input():
    return [int(_) for _ in input().split()]


def is_boardable(W, P, K):
    T = [0] * K

    wi = 0
    ti = 0
    while wi < len(W):
        if T[ti] + W[wi] <= P:
            T[ti] += W[wi]
            wi += 1
        else:
            ti += 1

            if ti == K:
                return False
    
    return True


def main():
    N, K = li_input()
    W = [int(input()) for _ in range(N)]

    l = 0
    r = 100000 * 10000

    while l + 1 < r:
        m = (l + r) // 2

        if is_boardable(W, m, K):
            P = m
            r = m
        else:
            l = m

    print(P)
    

main()

Submission status: Accepted

Solution code:
def allocation(A, k):
    def C(P):
        i = 0
        for j in range(k):
            s = 0  # current load for jth car
            while s + A[i] <= P:
                s += A[i]
                i += 1
                if i == len(A): return True
        return False

    l = 0
    r = 100000*10000  # [0..]
    while l !=r:
        mid = int((l + r) / 2)
        if C(mid):
            r = mid
        else:
            l = mid +1 
    return l

def main():
    N, k = (int(x) for x in input().split())
    A = [int(input()) for i in range(N)]
    print(allocation(A,k))


main()

Submission status: Accepted

Solution code:
#! /usr/local/bin/python3
# coding: utf-8

from math import floor
from sys import stdin

def allocate(n, k, w, P):
    n_truck = 1
    load = 0
    for wt in w:
        # print(n_truck, load, wt, P)
        if load + wt > P:
            n_truck += 1
            if n_truck > k:
                return False
            load = 0
        load += wt
    return True

def main():
    n, k = [int(x) for x in stdin.readline().split()]
    w = [int(x) for x in stdin]
    min_P = max(max(w), floor(sum(w) / k))
    max_P = sum(w)

    while min_P < max_P:
        mid_P = (min_P + max_P) // 2
        if allocate(n, k, w, mid_P):
            max_P = mid_P
        else:
            min_P = mid_P + 1
        # print(min_P, mid_P, max_P)
    
    print(min_P)

main()

Submission status: Accepted

Solution code:
def sum_of_list(A):
    sum = 0
    for i in A:
        sum += int(i)
    return sum

def load_number(A, p, k):
    capacity = p
    num = 0
    for i in A:
        if capacity < int(i):
            break
        elif p >= int(i) and k > 0:
            num += 1
            p -= int(i)
        elif p < int(i) and k > 1:
            num += 1
            k -= 1
            p = capacity
            p -= int(i)
        elif k == 0:
            break
    return num

def search_load_capacity(A, n, k):
    total_weight = sum_of_list(A)
    left = 0
    right = total_weight + 1
    while left < right:
        mid = int((left + right) / 2)
        if load_number(A, mid, k) >= n:
            if load_number(A, mid-1, k) < n:
                return mid
            else:
                right = mid
        else:
            left = mid + 1

n, k = (map(int,input().split()))
A = [input() for x in range(n)]
print(search_load_capacity(A, n, k))

Submission status: Accepted

Solution code:
import sys

#f = open("input.txt", 'r')
f = sys.stdin
i, k = f.readline().split()
k = int(k)

arr = []

for line in f:
    arr.append(int(line.split()[0]))

def chkCanLoad(arr, k, P):
    tmpW = 0
    k -= 1

    for w in arr:
        tmpW += w
        if tmpW > P:
            k = k - 1
            if k < 0:
                return False
            else:
                tmpW = w
                if tmpW > P:
                    return False
    return True

P = 1
maxP = -1
minP = -10
cof = 2 
while maxP != minP + 1:
    chk = chkCanLoad(arr, k, P)  
    if chk:
        maxP = P
        newP = int(minP + (maxP - minP)/cof)
        P = newP
    else:
        minP = P
        if maxP < 0:
            P *= cof
        else:
            newP = int(minP + (maxP - minP)/cof)
            P = newP 

print(maxP)

Submission status: Accepted

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


def solve(n, k, w):
    left = 0
    right = n * max(w)
    while right - left > 1:
        mid = (left + right) // 2
        v = check(n, k, w, mid)
        if v >= n:
            right = mid
        else:
            left = mid

    return right


n, k = [int(i) for i in input().split()]
w = [int(input()) for i in range(n)]
print(solve(n, k, w))

Submission status: Accepted

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

left=max(tmp)-1
right=sum(tmp)
while left+1 < right:
	mid=(left+right)//2
	count=1
	now=0
	for i in tmp:
		if mid<now+i:
			now=i
			count+=1
		else:
			now+=i

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

print(right)

Submission status: Accepted

Solution code:
# input() = input()
lines = '''\
5 3
8
1
7
3
9'''.split('\n')

# 方針　最大重量をPとしてPの場合に何個の荷物が全部で乗るか計算

def count(p,n,tracks,data):
  w = 0
  cnt = 0
  idx = 0
  while tracks > 0:
    if idx == n:
      break
    elif p >= data[idx] + w:
      w += data[idx]
      cnt += 1
      idx += 1
    else:
      tracks -= 1
      w = 0
  return cnt

n,tracks = [int(l) for l in input().split(' ')]
data = [int(input()) for i in range(n)]

# P の探索
wsum = 0
for dt in data:
  wsum += dt
wsum *= 2

def search(wsum,n,tracks,data):
  result = 0
  left = 0
  right = wsum
  while right - left > 1:
    mid = (left + right)//2
    v = count(mid,n,tracks,data)
    if v >= n:
      right = mid
    else:
      left = mid
  return right

r = search(wsum,n,tracks,data)
print(r)

Submission status: Accepted

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

def bs(n, k, W):
    left, right = max(W), sum(W)
    mid = 0
    while left < right:
        mid = left + (right - left) // 2
        if is_enough(mid, k, W):
            right = mid
        else:
            left = mid + 1
    return left

def is_enough(p, k, W):
    trk_cnt = 1
    weight = 0
    for i in W:
        weight += i
        if weight > p:
            trk_cnt += 1
            weight = i
            if trk_cnt > k:
                return False
    return True

def main():
    n, k = map(int, input().split())
    W = [int(input()) for _ in range(n)]
    rslt = bs(n, k, W)
    print(rslt)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n, tracks = list(map(int, input().split()))
loads = []
for _ in range(n):
    loads.append(int(input()))

# print(loads)
slices = []


def slicing(rest, s):
    if not rest:
        slices.append(s+[(s[-1][1], len(loads))])
        return

    first = len(s) and s[-1][1]
    for s1 in range(first+1, len(loads)-rest+1):
        slicing(rest-1, s+[(first, s1)])


slicing(tracks-1, [])
# print(slices)


def load_count_max(load):
    # print(load, max(sum(loads[l[0]: l[1]]) for l in load))
    return max(sum(loads[l[0]: l[1]]) for l in load)


result = min(map(load_count_max, slices))
print(result)

Submission status: Runtime Error

Solution code:
n, tracks = list(map(int, input().split()))
loads = []
for _ in range(n):
    loads.append(int(input()))

# print(loads)
slices = []
min_load = [99999999999999]


def slicing(rest, s):
    if not rest:
        # slices.append(s+[(len(s) and s[-1][1], len(loads))])
        s += [(len(s) and s[-1][1], len(loads))]
        min_load[0] = min(min_load[0], max(sum(loads[l[0]: l[1]]) for l in s))
        return

    first = len(s) and s[-1][1]
    for s1 in range(first+1, len(loads)-rest+1):
        total = sum(loads[first: s1])
        if total < min_load:
            slicing(rest-1, s+[(first, s1)])


slicing(tracks-1, [])
print(min_load.pop())

Submission status: Runtime Error

Solution code:
n, tracks = list(map(int, inpput().split()))
loads = []
for _ in range(n):
    loads.append(int(input()))

# print(loads)
slices = []
min_load = [99999999999999]

@lru_cache()
def slicing(rest, s=0):
    if not rest:
        # slices.append(s+[(len(s) and s[-1][1], len(loads))])
        return sum(loads[s:])

    result = 99999999999999
    for s1 in range(s+1, len(loads)-rest+1):
        result = min(result, max(sum(loads[s: s1]), slicing(rest-1, s1)))
    return result


rs = slicing(tracks-1)
print(rs)
# print(slices)


# def load_count_max(load):
#     print(load, max(sum(loads[l[0]: l[1]]) for l in load))
    # return max(sum(loads[l[0]: l[1]]) for l in load)


# result = min(map(load_count_max, slices))
# print(result)

Submission status: Runtime Error

Solution code:
n, tracks = list(map(int, input().split()))
loads = []
for _ in range(n):
    loads.append(int(input()))

# print(loads)
slices = []
min_load = [99999999999999]

@lru_cache()
def slicing(rest, s=0):
    if not rest:
        # slices.append(s+[(len(s) and s[-1][1], len(loads))])
        return sum(loads[s:])

    result = 99999999999999
    for s1 in range(s+1, len(loads)-rest+1):
        result = min(result, max(sum(loads[s: s1]), slicing(rest-1, s1)))
    return result


rs = slicing(tracks-1)
print(rs)
# print(slices)


# def load_count_max(load):
#     print(load, max(sum(loads[l[0]: l[1]]) for l in load))
    # return max(sum(loads[l[0]: l[1]]) for l in load)


# result = min(map(load_count_max, slices))
# print(result)

Submission status: Runtime Error

Solution code:
def check(T, p, n, k):
    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

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

left, right = 0, 100000 * 10000

while(right - left > 1):
    mid = (left + right) / 2
    if (check(mid) >= n):
        right = mid
    else:
        left = mid

print right

Submission status: Runtime Error

Solution code:
def check(T, p, n, k):
    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

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

left, right = 0, 100000 * 10000

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

print right

Submission status: Runtime Error

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

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

  left = 0
  right = 100000*10000
  while left<right:
    mid = (right + left)/2

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

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

print right

Submission status: Runtime Error

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

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

  left = 0
  right = 100000*10000
  while left<right:
    mid = (right + left)/2

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

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

print right

Submission status: Runtime Error

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

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

  left = 0
  right = 100000*10000
  while left<right:
    mid = (right + left)/2

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

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

print right

Submission status: Runtime Error

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++
      if j == n:
        break

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

print right

Submission status: Runtime Error

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++
      if j == n:
        break

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

print right

Submission status: Runtime Error

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: Runtime Error

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 k in range(k)
    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: Runtime Error

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 k in range(k):
    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: Runtime Error

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
    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: Runtime Error

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
    while s + T[j] <= mid:
      s += T[j]
      j += 1
      if j == n:
        x = -1
        break
    if x = -1:
      break

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

print right

Submission status: Runtime Error

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
    while s + T[j] <= mid:
      s += T[j]
      j += 1
      if j == n:
        d = -1
        break
    if d = -1:
      break

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

print right

Submission status: Runtime Error

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
    while s + T[j] <= mid:
      s += T[j]
      j += 1


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

print right

Submission status: Runtime Error

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
    while s + T[j] <= mid:
      s = s + T[j]
      j = j + 1
      if j == n:
        break

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

print right

Submission status: Runtime Error

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
    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: Runtime Error

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
    while s+T[j] <= mid or j == n:
      s += T[j]
      j += 1
#      if j == n:


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

print right

Submission status: Runtime Error

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
    while s+T[j] <= mid or j == n:
      s += T[j]
      j += 1

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

print right

Submission status: Runtime Error

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
    while s+T[j] <= mid or j == n-1:
      s += T[j]
      j += 1

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

print right

Submission status: Runtime Error

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
    while s+T[j] <= mid or j != n-1:
      s += T[j]
      j += 1

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

print right

Submission status: Runtime Error

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
    while s+T[j] <= mid or j not n-1:
      s += T[j]
      j += 1

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

print right

Submission status: Runtime Error

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
    while s+T[j] <= mid or j not n-1:
#      s += T[j]
#      j += 1

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

print right

Submission status: Runtime Error

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
    while s+T[j] <= mid or j := n-1:
#      s += T[j]
#      j += 1

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

print right

Submission status: Runtime Error

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
    while s+T[j] <= mid or j ::= n-1:
#      s += T[j]
#      j += 1

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

print right

Submission status: Runtime Error

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
    while s+T[j] <= mid or j is not n-1:
#      s += T[j]
#      j += 1

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

print right

Submission status: Runtime Error

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
    while s+T[j] <= mid or j is not n-1:
      s += T[j]
      j += 1

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

print right

Submission status: Runtime Error

Solution code:
def moveRight(trug, start, stop):
    if trug[start][1]-trug[start][0] > 1:
        for i in xrange(stop-start):
            trug[start+i][1] -= 1
            trug[start+i+1][0] -= 1

def moveLeft(trug, start, stop):
    if trug[start][1]-trug[start][0] > 1:
        for i in xrange(start-stop):
            trug[start-i][0] += 1
            trug[start-i-1][1] += 1

def calcWeight(trug, w):
    temp = [ sum(w[trug[i][0]:trug[i][1]]) for i in xrange(len(trug)) ]
    return temp

n, k = map(int, raw_input().split())
w = []
for i in xrange(n):
    w.append(input())

ta = n/k
trug = [[i*ta, ta+i*ta] for i in xrange(k-1)]
trug.append([(i+1)*ta, n])

trugw = calcWeight(trug, w)
maxt  = max(trugw)
imaxt = trugw.index(maxt)
mint  = min(trugw)
imint = trugw.index(mint)

while True:
    if imaxt < imint:
        if mint+w[trug[imaxt][1]-1] < maxt:
            moveRight(trug, imaxt, imint)
    else:
        if mint+w[trug[imaxt][0]] < maxt:
            moveLeft(trug, imaxt, imint)

    trugw = calcWeight(trug, w)
    n = max(trugw)
    if n >= maxt:
        break
    else:
        maxt  = n
        imaxt = trugw.index(maxt)
        mint = min(trugw)
        imint = trugw.index(mint)

print maxt

Submission status: Runtime Error

Solution code:
def moveRight(trug, start, stop):
    if trug[start][1]-trug[start][0] > 1:
        for i in xrange(stop-start):
            trug[start+i][1] -= 1
            trug[start+i+1][0] -= 1

def moveLeft(trug, start, stop):
    if trug[start][1]-trug[start][0] > 1:
        for i in xrange(start-stop):
            trug[start-i][0] += 1
            trug[start-i-1][1] += 1

def calcWeight(trug, w):
    temp = [ sum(w[trug[i][0]:trug[i][1]]) for i in xrange(len(trug)) ]
    return temp

n, k = map(int, raw_input().split())
w = []
for i in xrange(n):
    w.append(input())

if k == 1:
    trug = [[0, n]]
else:
    ta = n/k
    trug = [[i*ta, ta+i*ta] for i in xrange(k-1)]
    trug.append([(i+1)*ta, n])

trugw = calcWeight(trug, w)
maxt  = max(trugw)
imaxt = trugw.index(maxt)
mint  = min(trugw)
imint = trugw.index(mint)

while True:
    if imaxt < imint:
        if mint+w[trug[imint-1][1]-1] < maxt:
            moveRight(trug, imaxt, imint)
    else:
        if mint+w[trug[imint+1][0]] < maxt:
            moveLeft(trug, imaxt, imint)

    trugw = calcWeight(trug, w)
    n = max(trugw)
    if n >= maxt:
        break
    else:
        maxt  = n
        imaxt = trugw.index(maxt)
        mint = min(trugw)
        imint = trugw.index(mint)

print maxt

Submission status: Runtime Error

Solution code:
def cal(truck_num, cargos):
    p = []
    
    for i in range(len(cargos) - truck_num + 1):
        if truck_num > 1:
            p.append(max(sum(cargos[:i + 1]), cal(truck_num - 1, cargos[i + 1:])))
        else:
            return sum(cargos)
    return min(p)

if __name__ == "__main__":
    line = input()
    truck_num = line.split(" ")[1]
    line_num = line.split(" ")[0]
    cargos = []
    for cargos in range(line_num):
        cargos.append(int(input()))
    print(cal(truck_num,cargos))

Submission status: Runtime Error

Solution code:
def calc_k(p, ws):
    k = 1
    s = 0
    for w in ws:
        if w > p:
            return None
        elif s + w <= p:
            s += w
        else:
            k += 1
            s = w
    return k

def search_minimum_p_internal(lp, rp, k, ws):
    "?????????P????????????????????¢?´¢??????"
    cp = (lp + rp) // 2
    k1 = calc_k(cp, ws)
    if k1 == k:
        # ???????????¨????????????????°?????????¨???k??°????????????????????????
        k2 = calc_k(cp - 1, ws)
        if k2 == None or k2 > k:
            # cp???k??°???????????????????????????p???????°??????§??????
            return cp
        else:
            # ???????°???????p????????¨??????
            return search_minimum_p_internal(lp, cp - 1, k, ws)
    elif k1 < k:
        # ???????????¨???????????????k??°???????°?????????????????????§????????????????????????????????????
        return search_minimum_p_internal(lp, cp - 1, k, ws)
    else:
        # ???????????¨???????????????k??°????????????????????????????????????????????????????¶?????????????
        return search_minimum_p_internal(cp + 1, rp, k, ws)

def search_minimum_p(k, ws):
    """
    max(P) = max(wi) * max(n)
    ????????¨???????????????1??°?????¨????????????????????????
    min(P) = max(wi)
    ?°?????????¨??????????????????????????§????????????????????????????????????
    """
    maxp = 10000 * 100000
    minp = max(ws)
    return search_minimum_p_internal(minp, maxp, k, ws)

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

print(search_minimum_p(k, ws))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
ww = [int(input()) for _ in range(n)]
def chk(p):
    c = 1
    s = 0
    for w in ww:
        if w > p:
            return False
        if s + w <= p:
            s += w
        else:
            c += 1
            s = w
    return c <= k
def search(l, r):
    if r - l < 10:
        for i in range(l, r):
            if chk(i):
                return i
    m = (l + r) // 2
    if chk(m):
        return search(l, m)
    else:
        return search(m, r)
print(search(0, 2 ** 30))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
ww = [int(input()) for _ in range(n)]
def chk(p):
    c = 1
    s = 0
    for w in ww:
        if w > p:
            return False
        if s + w <= p:
            s += w
        else:
            c += 1
            s = w
        if c > k:
            return False
    return True
def search(l, r):
    if r - l < 10:
        for i in range(l, r):
            if chk(i):
                return i
    m = (l + r) // 2
    if chk(m):
        return search(l, m)
    else:
        return search(m, r)
print(search(0, 2 ** 30))

Submission status: Runtime Error

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_9_B
#???????????? 17:55~

def maxHeapify(heap, index):
    left_index = 2 * index
    right_index = 2 * index + 1

    if left_index < len(heap) and heap[left_index] > heap[index]:
        largest_index = left_index
    else:
        largest_index = index

    if right_index < len(heap) and heap[right_index] > heap[largest_index]:
        largest_index = right_index

    if not largest_index == index:
        heap[index], heap[largest_index] = heap[largest_index], heap[index]
        maxHeapify(heap, largest_index)
    
def main():
    n_node = int(input())
    target_list = [""] + [int(n) for n in input().split()]
    for i in range(int(len(target_list) / 2), 0, -1):
        print(i)
        maxHeapify(target_list, i)
        
    print(*target_list)
if __name__ == "__main__":
    main()