Help me in solving MAXIMALEXP problem

My issue

what is fault in my code? why it is giving runtime error

My code

#include <iostream>
using namespace std;

int main() {
    long long int T,N,K;
	cin>>T;
	for(int i=0;i<T;i++)
	{
	    cin>>N>>K;
	    long long int arr[N];
	    for(int j=0;j<N+1;j++)
	    {
	        arr[j]=(j%K)*((N-j)%K);
	       
	    }
	    long long int max=-1,c=-1;
	    for(int z=0;z<N+1;z++)
	    {
	         if(arr[z]>max)
	        {
	            max=arr[z];
	            c=z;
	        }
	    }
	    cout<<c<<endl;;
	    
	    
	    
	}
	return 0;
}

Problem Link: MAXIMALEXP Problem - CodeChef