#include
using namespace std;
define ll long long
int main()
{
ll n,k;
ll dp[2000005],mx[2000005],a[2000005];
cin>>n>>k;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
dp[0]=a[0];
mx[0]=a[0];
for(int i=1;i<n;i++)
{
if(i<k)
{
dp[i]=a[i];
}
else
{
dp[i] = mx[i-k] + a[i];
}
mx[i] = max(dp[i],mx[i-1]);
}
cout<<max(0LL,mx[n-1])<<"\n";
return 0;
}
Why is this code throwing error ? Is it conceptually wrong ?