Max Sum K-Partition is this true code

#include
#include <bits/stdc++.h>
using namespace std;

#define ll long long
ll n , k , arr[2000002] , dp[2000002];
ll maximise_sum(int i)
{
if(i >= n)
{
return 0;
}
if(dp[i] != -1)
{
return dp[i];
}
ll x = INT_MIN;
ll mul = i/k + 1;
for(ll a = mul*k ; a < (mul+1)*k ;a++)
{
if(a == i+k)
{
continue;
}
x = max(x , maximise_sum(a));
}
return dp[i] = max(arr[i] + x , maximise_sum(i+1));
}
int main()
{
ll i = 0;
cin>>n>>k;
while(i < n)
{
cin>>arr[i];
i++;
}
memset(dp , -1 , sizeof(dp));
cout<<maximise_sum(0)<<endl;
for(int i =0 ; i < n ; i++)
{
cout<<dp[i]<<" ";
}
return 0;
}

Hey @ssanjuchandra
You can verify with this https://ide.codingblocks.com/s/185478
If your doubt is resolved please mark it as closed.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.