forked from Shubham28/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMAXSUMSQ.cpp
69 lines (52 loc) · 1008 Bytes
/
MAXSUMSQ.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstdlib>
#define FOR(A,B,C) for(int A=B;A<C;A++)
#define EFOR(A,B,C) for(int A=B;A<=C;A++)
#define RFOR(A,B,C) for(int A=B;A>=C;A--)
#define LL long long
using namespace std;
inline void Input(int &N)
{
int ch,sign;
N=0;
while((ch<'0' || ch>'9') && ch!='-' && ch!=EOF)
ch=getchar();
if(ch=='-')
sign=-1,ch=getchar();
else
sign=1;
do
N=(N<<3)+(N<<1)+(ch-'0');
while((ch=getchar())>='0' && ch<='9');
N*=sign;
return;
}
int main()
{
int T,N;
int ar[100001];
LL ans,tot;
LL mxsum[100001],cnt[100001];
Input(T);
while(T--){
Input(N);
FOR(inp,0,N)
Input(ar[inp]);
mxsum[0]=ar[0],cnt[0]=1;
ans=mxsum[0],tot=0;
FOR(i,1,N){
mxsum[i]=ar[i],cnt[i]=1;
if(mxsum[i-1]>0)
mxsum[i]+=mxsum[i-1],cnt[i]=cnt[i-1];
else if(mxsum[i-1]==0)
cnt[i]+=cnt[i-1];
ans=max(ans,mxsum[i]);
}
FOR(fnd,0,N)
tot+=((mxsum[fnd]==ans)?cnt[fnd]:0);
printf("%lld %lld\n",ans,tot);
}
return 0;
}