Help me in solving MAXIMALEXP problem

My issue

I’m getting problem in runtime error so can anyone discuss the answer with me

My code

#include <iostream>
using namespace std;

int main() {
	
	int t,n,k,num,den;
	cin>>t;
	while(t--){
	    cin>>n>>k;
	  
	    int Fx[n];
	    for(int i=0;i<=n;i++){
	        num = (i % k) ;
	        den = ((n-i) % k);
	        Fx[i] = num * den;
	    }
	    int max = 0,index;
	    for(int i=0;i<=n;i++){
	        if(Fx[i] >= max){
	            max = Fx[i];
	            index = i;
	        }
	    }
	    cout<<index<<endl;
	    
	}
	return 0;
}

Problem Link: MAXIMALEXP Problem - CodeChef

n and k can have values up to the 10raise to the power 9 and you cannot run a loop that much times. Thats why it is showing runtime error.

1 Like

accesing nth index for which memory is not allocated .taking f[n+1]

1 Like