What's the problem in this code?

It is passing the test case but no submit test cases.help please

#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int arr[n];
int sum[n] = {0};
cin>>arr[0];
sum[0] = arr[0];
for(int i = 1;i<n;i++)
{
int k;
cin>>k;
arr[i] = k;
sum[i]+= sum[i-1] + k;
}
sort(sum,sum+n);

	int maximum = max(sum[n-1],sum[n-1] - sum[0]);
	cout<<maximum<<endl;
}
return 0;

}

hello @alamsarfraz422
a)
ur logic is only checking for maximum prefix sum subarray but subarray that are not prefix can also be maximum.

b) dont sort the prefix array as it will change the order.
for example->
if array is -> 8 -10
then ur prefix array will be -> 8 -2
and when u will sort it , it will be -> -2 8
and then as per ur logic it will give 10 as answer which is clearly wrong.

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.