-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP171SUME.cpp
More file actions
45 lines (37 loc) · 1.01 KB
/
P171SUME.cpp
File metadata and controls
45 lines (37 loc) · 1.01 KB
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
#include<bits/stdc++.h>
using namespace std;
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Ford(i, a, b) for(int i = a; i >= b; i--)
#define ll long long
#define here cout<<"I am Here"<<endl;
int const maxn = 1000000;
int const base = 1e9 + 7;
int maxSubArraySum(int a[], int size){
int max_so_far = 0, max_ending_here = 0;
for (int i = 0; i < size; i++){
max_ending_here = max_ending_here + a[i];
if (max_ending_here < 0)
max_ending_here = 0;
else if (max_so_far < max_ending_here)
max_so_far = max_ending_here;
}
return max_so_far;
}
int Ar[100000], n;
int main(void){
int maxs = -100000;
int Sum = 0;
cin>>n;
For(i, 0, n - 1){
cin>>Ar[i];
if(Ar[i] > 0){
Sum += Ar[i];
}
if(Ar[i] > maxs) maxs = Ar[i];
}
if(Sum == 0) Sum = maxs;
int S = maxSubArraySum(Ar, n);
if(S == 0) S = maxs;
cout<<S<<" "<<Sum;
return 0;
}