-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubarray.cpp
More file actions
53 lines (43 loc) · 769 Bytes
/
subarray.cpp
File metadata and controls
53 lines (43 loc) · 769 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
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin>>n;
long long count=0;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
long long int max1=INT_MIN;
long long int max_ending =0;
for(int i=0;i<n;i++)
{
max_ending = max_ending +a[i];
if(max1<max_ending)
{
max1=max_ending;
count=0;
}
if(max1==max_ending)
{
count++;
}
if(max_ending<0)
{
max_ending=0;
}
}
if(max1<0)
{
cout<<"0 0"<<endl;
}
else
{
cout<<max1<<" "<<count<<endl;
}
}