-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultivengers.cpp
More file actions
47 lines (43 loc) · 889 Bytes
/
multivengers.cpp
File metadata and controls
47 lines (43 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
#include<algorithm>
using namespace std;
long long maxSum(long long a[], long size)
{
long long max = LONG_LONG_MIN, new_max = 0;
for (long long i = 0; i < size; i++)
{
new_max = new_max + a[i];
if (max < new_max)
max = new_max;
if (new_max < 0)
new_max = 0;
}
return max;
}
int main()
{
long long M = 1000000007;
long long tc,n,c=0;
cin>>tc;
while(tc>0)
{
cin>>n;
long long ar[n];
for(long long i=0;i<n;++i)
{
cin>>ar[i];
if(ar[i]>0)
++c;
}
if(c==0)
cout<<*max_element(ar, ar + n) % M<<endl;
else
{
long long s= sizeof(ar)/sizeof(ar[0]);
long long max_sum = maxSum(ar, s);
cout<<(max_sum)%M<<endl;
}
--tc;
}
return 0;
}