# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        product_num = int(self.__input[0].split()[0])
        truck_num = int(self.__input[0].split()[1])
        weight_list = list(map(int, self.__input[1:]))

        assert product_num == len(weight_list)

        # binary search
        left, right, mid = max(weight_list), sum(weight_list), 0
        while left < right:
            mid = (left + right) // 2
            # check return True : p could be smaller
            if self.check(mid, weight_list, truck_num):
                right = mid
            else:
                mid += 1
                left = mid
        return str(mid)

    @staticmethod
    def check(max_load_cursor, weight_list, truck_num):
        track_count = 1
        current_load = 0
        for item_weight in weight_list:
            current_load += item_weight
            # change to next truck
            if current_load > max_load_cursor:
                current_load = item_weight
                track_count += 1
                if track_count > truck_num:
                    return False
        return True


if __name__ == '__main__':
    case = Solution()
    print(case.solution) import sys sys class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        product_num = int(self.__input[0].split()[0])
        truck_num = int(self.__input[0].split()[1])
        weight_list = list(map(int, self.__input[1:]))

        assert product_num == len(weight_list)

        # binary search
        left, right, mid = max(weight_list), sum(weight_list), 0
        while left < right:
            mid = (left + right) // 2
            # check return True : p could be smaller
            if self.check(mid, weight_list, truck_num):
                right = mid
            else:
                mid += 1
                left = mid
        return str(mid)

    @staticmethod
    def check(max_load_cursor, weight_list, truck_num):
        track_count = 1
        current_load = 0
        for item_weight in weight_list:
            current_load += item_weight
            # change to next truck
            if current_load > max_load_cursor:
                current_load = item_weight
                track_count += 1
                if track_count > truck_num:
                    return False
        return True Solution def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

     __init__ """
        init input array
        """ self.__input = sys.stdin.readlines() self.__input self __input sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines self self def solution(self):
        product_num = int(self.__input[0].split()[0])
        truck_num = int(self.__input[0].split()[1])
        weight_list = list(map(int, self.__input[1:]))

        assert product_num == len(weight_list)

        # binary search
        left, right, mid = max(weight_list), sum(weight_list), 0
        while left < right:
            mid = (left + right) // 2
            # check return True : p could be smaller
            if self.check(mid, weight_list, truck_num):
                right = mid
            else:
                mid += 1
                left = mid
        return str(mid)

     solution product_num = int(self.__input[0].split()[0]) product_num int(self.__input[0].split()[0]) int self.__input[0].split()[0] self.__input[0].split() self.__input[0].split self.__input[0] self.__input self __input 0 split 0 truck_num = int(self.__input[0].split()[1]) truck_num int(self.__input[0].split()[1]) int self.__input[0].split()[1] self.__input[0].split() self.__input[0].split self.__input[0] self.__input self __input 0 split 1 weight_list = list(map(int, self.__input[1:])) weight_list list(map(int, self.__input[1:])) list map(int, self.__input[1:]) map int self.__input[1:] self.__input self __input 1: 1 assert product_num == len(weight_list) product_num == len(weight_list) product_num len(weight_list) len weight_list left, right, mid = max(weight_list), sum(weight_list), 0 left max(weight_list) max weight_list right sum(weight_list) sum weight_list mid 0 while left < right:
            mid = (left + right) // 2
            # check return True : p could be smaller
            if self.check(mid, weight_list, truck_num):
                right = mid
            else:
                mid += 1
                left = mid
         left < right left right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 if self.check(mid, weight_list, truck_num):
                right = mid
            else:
                mid += 1
                left = mid
         self.check(mid, weight_list, truck_num) self.check self check mid weight_list truck_num right = mid right mid mid += 1 mid 1 left = mid left mid return str(mid) str(mid) str mid self self @property
     solution property solution def check(max_load_cursor, weight_list, truck_num):
        track_count = 1
        current_load = 0
        for item_weight in weight_list:
            current_load += item_weight
            # change to next truck
            if current_load > max_load_cursor:
                current_load = item_weight
                track_count += 1
                if track_count > truck_num:
                    return False
        return True check track_count = 1 track_count 1 current_load = 0 current_load 0 for item_weight in weight_list:
            current_load += item_weight
            # change to next truck
            if current_load > max_load_cursor:
                current_load = item_weight
                track_count += 1
                if track_count > truck_num:
                    return False
         item_weight weight_list current_load += item_weight current_load item_weight if current_load > max_load_cursor:
                current_load = item_weight
                track_count += 1
                if track_count > truck_num:
                    return False
         current_load > max_load_cursor current_load max_load_cursor current_load = item_weight current_load item_weight track_count += 1 track_count 1 if track_count > truck_num:
                    return False
         track_count > truck_num track_count truck_num return False False return True True max_load_cursor max_load_cursor weight_list weight_list truck_num truck_num @staticmethod
     check staticmethod check if __name__ == '__main__':
    case = Solution()
    print(case.solution) __name__ == '__main__' __name__ '__main__' case = Solution() case Solution() Solution print(case.solution) print case.solution case solution case = Solution() Solution() case class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        product_num = int(self.__input[0].split()[0])
        truck_num = int(self.__input[0].split()[1])
        weight_list = list(map(int, self.__input[1:]))

        assert product_num == len(weight_list)

        # binary search
        left, right, mid = max(weight_list), sum(weight_list), 0
        while left < right:
            mid = (left + right) // 2
            # check return True : p could be smaller
            if self.check(mid, weight_list, truck_num):
                right = mid
            else:
                mid += 1
                left = mid
        return str(mid)

    @staticmethod
    def check(max_load_cursor, weight_list, truck_num):
        track_count = 1
        current_load = 0
        for item_weight in weight_list:
            current_load += item_weight
            # change to next truck
            if current_load > max_load_cursor:
                current_load = item_weight
                track_count += 1
                if track_count > truck_num:
                    return False
        return True class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        product_num = int(self.__input[0].split()[0])
        truck_num = int(self.__input[0].split()[1])
        weight_list = list(map(int, self.__input[1:]))

        assert product_num == len(weight_list)

        # binary search
        left, right, mid = max(weight_list), sum(weight_list), 0
        while left < right:
            mid = (left + right) // 2
            # check return True : p could be smaller
            if self.check(mid, weight_list, truck_num):
                right = mid
            else:
                mid += 1
                left = mid
        return str(mid)

    @staticmethod
    def check(max_load_cursor, weight_list, truck_num):
        track_count = 1
        current_load = 0
        for item_weight in weight_list:
            current_load += item_weight
            # change to next truck
            if current_load > max_load_cursor:
                current_load = item_weight
                track_count += 1
                if track_count > truck_num:
                    return False
        return True Solution
# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        product_num = int(self.__input[0].split()[0])
        truck_num = int(self.__input[0].split()[1])
        weight_list = list(map(int, self.__input[1:]))

        assert product_num == len(weight_list)

        # binary search
        left, right, mid = max(weight_list), sum(weight_list), 0
        while left < right:
            mid = (left + right) // 2
            # check return True : p could be smaller
            if self.check(mid, weight_list, truck_num):
                right = mid
            else:
                mid += 1
                left = mid
        return str(mid)

    @staticmethod
    def check(max_load_cursor, weight_list, truck_num):
        track_count = 1
        current_load = 0
        for item_weight in weight_list:
            current_load += item_weight
            # change to next truck
            if current_load > max_load_cursor:
                current_load = item_weight
                track_count += 1
                if track_count > truck_num:
                    return False
        return True


if __name__ == '__main__':
    case = Solution()
    print(case.solution)