setting = input().split();
package_count = int(setting[0]);
truck_count = int(setting[1]);
packages = [];
for i in range(package_count):
    packages.append(int(input()));

def allocation():
    max_p = sum(packages);
    left = 0;
    right = max_p;
    while left < right:
        mid = (left + right) // 2;
        load = calculate_load(mid);
        if load >= package_count:
            right = mid;
        else:
            left = mid + 1;
    return right;

def calculate_load(p):
    i = 0;
    j = 0;
    current_truck_p = p;
    while i < package_count and j < truck_count:
        if packages[i] <= current_truck_p:
            current_truck_p -= packages[i];
            i += 1;
        else:
            j += 1;
            current_truck_p = p;
    return i;

print(allocation()); setting = input().split() setting input().split() ().split () input split package_count = int(setting[0]) package_count int(setting[0]) int setting[0] setting 0 truck_count = int(setting[1]) truck_count int(setting[1]) int setting[1] setting 1 packages = [] packages [] for i in range(package_count):
    packages.append(int(input())); i range(package_count) range package_count packages.append(int(input())) packages.append packages append int(input()) int input() input def allocation():
    max_p = sum(packages);
    left = 0;
    right = max_p;
    while left < right:
        mid = (left + right) // 2;
        load = calculate_load(mid);
        if load >= package_count:
            right = mid;
        else:
            left = mid + 1;
    return right; allocation max_p = sum(packages) max_p sum(packages) sum packages left = 0 left 0 right = max_p right max_p while left < right:
        mid = (left + right) // 2;
        load = calculate_load(mid);
        if load >= package_count:
            right = mid;
        else:
            left = mid + 1;
     left < right left right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 load = calculate_load(mid) load calculate_load(mid) calculate_load mid if load >= package_count:
            right = mid;
        else:
            left = mid + 1;
     load >= package_count load package_count right = mid right mid left = mid + 1 left mid + 1 mid 1 return right right def calculate_load(p):
    i = 0;
    j = 0;
    current_truck_p = p;
    while i < package_count and j < truck_count:
        if packages[i] <= current_truck_p:
            current_truck_p -= packages[i];
            i += 1;
        else:
            j += 1;
            current_truck_p = p;
    return i; calculate_load i = 0 i 0 j = 0 j 0 current_truck_p = p current_truck_p p while i < package_count and j < truck_count:
        if packages[i] <= current_truck_p:
            current_truck_p -= packages[i];
            i += 1;
        else:
            j += 1;
            current_truck_p = p;
     i < package_count and j < truck_count i < package_count i package_count j < truck_count j truck_count if packages[i] <= current_truck_p:
            current_truck_p -= packages[i];
            i += 1;
        else:
            j += 1;
            current_truck_p = p;
     packages[i] <= current_truck_p packages[i] packages i current_truck_p current_truck_p -= packages[i] current_truck_p packages[i] packages i i += 1 i 1 j += 1 j 1 current_truck_p = p current_truck_p p return i i p p print(allocation()) print allocation() allocation setting = input().split() input().split() setting package_count = int(setting[0]) int(setting[0]) package_count truck_count = int(setting[1]) int(setting[1]) truck_count def allocation():
    max_p = sum(packages);
    left = 0;
    right = max_p;
    while left < right:
        mid = (left + right) // 2;
        load = calculate_load(mid);
        if load >= package_count:
            right = mid;
        else:
            left = mid + 1;
    return right; def allocation():
    max_p = sum(packages);
    left = 0;
    right = max_p;
    while left < right:
        mid = (left + right) // 2;
        load = calculate_load(mid);
        if load >= package_count:
            right = mid;
        else:
            left = mid + 1;
    return right; allocation packages = [] [] packages def calculate_load(p):
    i = 0;
    j = 0;
    current_truck_p = p;
    while i < package_count and j < truck_count:
        if packages[i] <= current_truck_p:
            current_truck_p -= packages[i];
            i += 1;
        else:
            j += 1;
            current_truck_p = p;
    return i; def calculate_load(p):
    i = 0;
    j = 0;
    current_truck_p = p;
    while i < package_count and j < truck_count:
        if packages[i] <= current_truck_p:
            current_truck_p -= packages[i];
            i += 1;
        else:
            j += 1;
            current_truck_p = p;
    return i; calculate_load
setting = input().split();
package_count = int(setting[0]);
truck_count = int(setting[1]);
packages = [];
for i in range(package_count):
    packages.append(int(input()));

def allocation():
    max_p = sum(packages);
    left = 0;
    right = max_p;
    while left < right:
        mid = (left + right) // 2;
        load = calculate_load(mid);
        if load >= package_count:
            right = mid;
        else:
            left = mid + 1;
    return right;

def calculate_load(p):
    i = 0;
    j = 0;
    current_truck_p = p;
    while i < package_count and j < truck_count:
        if packages[i] <= current_truck_p:
            current_truck_p -= packages[i];
            i += 1;
        else:
            j += 1;
            current_truck_p = p;
    return i;

print(allocation());
