public int maxSumAfterPartitioning(int[] arr, int k) {
int maxn = 110;
int dp[] = new int[maxn];
int len = arr.length;
int maxNum;
int cnt;
for(int i=0;i<len;i++){
dp[i] = 0;
maxNum = 0;
cnt = 0;
for(int j=i;j>=0;j--){
if(arr[j]>maxNum){
maxNum = arr[j];
}
cnt++;
if(cnt>k){
break;
}
if(j!=0){
dp[i] = Math.max(dp[j-1]+cnt*maxNum,dp[i]);
}else{
dp[i] = Math.max(dp[i],cnt*maxNum) ;
}
}
}
return dp[len-1];
}