#include
using namespace std;
bool isvalid(int arr[],int no_of_student,int no_of_books,int ans)
{
int std=1,current_pages=0;
for(int i=0;i<no_of_books;i++)
{
if(current_pages>ans)
{
std++;
current_pages=arr[i];
}
else
{
current_pages=current_pages+arr[i];
}
if(std>no_of_student)
return false;
}
return true;
}
int main()
{
int no_of_books,no_of_student,sum=0;
cin>>no_of_books;
int arr[no_of_books];
for(int i=0;i<no_of_books;i++)
{
cin>>arr[i];
sum=sum+arr[i];
}
cin>>no_of_student;
int start =0,end=sum,final_ans,mid=0;
while(start<=end)
{
mid=(start+end)/2;
if(isvalid(arr,no_of_student,no_of_books,mid))
{
end=mid-1;
final_ans=mid;
}
else start=mid+1;
}
cout<<final_ans;
}