Please tell me what is wrong with my code.
import java.util.*;
public class Main {
public static long partition(long []arr,long max,long sum,long h)
{
long start=max,end=sum,mid=0,ans=sum;
while(start<=end)
{
mid=start+(end-start)/2;
long k=trackPainters(arr,mid);
if(h>=k) {
if(ans>mid)
{
ans=mid;
}
end=mid-1;
}
else if (k > h)
start = mid + 1;
}
return ans;
}
private static long trackPainters(long[] arr, long mid) {
int i, k = 1;
long sum1 = 0;
for (i = 0; i < arr.length; i++) {
sum1 += arr[i];
if (sum1 > mid) {
k++;
sum1 = arr[i];
}
}
return k;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
long arr[]=new long[n];
for(int i=0;i<n;i++)
{
arr[i]=sc.nextLong();
}
long max=Integer.MIN_VALUE,sum=0;
for(int i=0;i<n;i++)
{
if(max<arr[i])
{
max=arr[i];
}
sum+=arr[i];
}
if(k>=n)
{
System.out.println(max);
}
else
{
System.out.println(partition(arr, max, sum, k));
}
}
}