How can I correct this code?

#include< iostream >

#include< climits >

using namespace std;

int ans(double a[100000], int n){

int max_sum = INT_MIN ;

for(int i=0; i<n; i++){
	for(int j=i; j<n; j++){

		int sum = 0 ;
		for(int k=i; k<=j; k++){
			// cout << a[k];
			sum += a[k] ;
		}
		// cout << sum << endl ;
		if(sum > max_sum){
			max_sum = sum ;
		}
	}
}
return max_sum ;

}

int main() {
int t ,n;
cin >> t;

if(t>=1 && t<=20){
 double a[100000];

 for(int i=1; i<=t; i++){
	 cin >> n;
	
	 for(int j=0; j<n; j++){
		 cin >> a[j] ;
	    }

	 cout << ans(a,n) << endl ;
    }
}


return 0;

}

// It is not satisfying all test cases so kindly correct it . Also is their any other better approach for the same question.

hello @arshia27

the time complexity of ur algorithm is O(N^3) , That why it is not passing all case

yeah using kadane algorithm u can solve it in O(N).
pls check ur playlist, this algorithm is covered in ur course

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.