Max sum subarray

Question
You are given a one dimensional array that may contain both positive and negative integers, find the sum of contiguous subarray of numbers which has the largest sum. For example, if the given array is {-2, -5, 6, -2, -3, 1, 5, -6}, then the maximum subarray sum is 7.

Input Format:
The first line consists of number of test cases T. Each test case consists of N followed by N integers.

Constraints:
1 <= N <= 100000
1 <= t <= 20
0 <= A[i] <= 100000000
Output Format:
The maximum subarray sum

#include
using namespace std;
int main() {
int t;
cin >> t ;

while(t--){
int n;
cin >> n;

int arr[100];

int cs=0;
int ms=0;

for(int i=0; i<n ;i++){
    cin >> arr[i];
}
for(int i=0; i<n ;i++){
    cs+=arr[i];
    if(cs<0){
        cs=0;
    }
    ms=max(ms,cs);
}
cout << "max sum: "<<ms<<endl;
}

}
it is showing run-error in hacker blocks but ouputs is showing correct

runtime error is due to size of arr[100]. number of inputs i.e. n is greater than 100 and thus it is producing error.
Change that line to int arr[1000000];

now its showing wrong answer but answer is coming right

use long long instead of int.
And send me the problem link along with the code link so that i can verify in case it is not working.

https://hack.codingblocks.com/contests/c/512/1259

#include
using namespace std;
int main() {
int t;
cin >> t ;

while(t–){
long long int n;
cin >> n;

int arr[1000000];

int cs=0;
int ms=0;

for(int i=0; i<n ;i++){
cin >> arr[i];
}
for(int i=0; i<n ;i++){
cs+=arr[i];
if(cs<0){
cs=0;
}
ms=max(ms,cs);
}
cout << "max sum: "<<ms<<endl;
}
}

still not working

Make arr, cs and ms as long long int.


now its not running and in sumitting showing wrong-ans

question never asked to cout “max sum:”.
Your output is compared word by word with the output file and if you write unnecessary output statements, it wont give correct answer. remove that cout.

why ms and cs is having long long int
we just create it to store the value

because the answer is quite large and requires long long to store it.