FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Competitive-Programming/Algorithms/MxxSubArraySum.java at master · joney000/Java-Competitive-Programming · GitHub
joney000
/
Java-Competitive-Programming
Public
Notifications
You must be signed in to change notification settings
Fork
30
Star
123
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Competitive-Programming
/
Algorithms
/
MxxSubArraySum.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
52 lines (40 loc) · 1.18 KB
Breadcrumbs
Java-Competitive-Programming
/
Algorithms
/
MxxSubArraySum.java
Copy path
File metadata and controls
executable file
·
52 lines (40 loc) · 1.18 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/* package joney_000 */
import
java
.
util
.*;
import
java
.
lang
.*;
import
java
.
io
.*;
import
java
.
math
.*;
class
MaxSubArraySum
{
public
static
long
ans
=
0
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
));
BufferedWriter
out
=
new
BufferedWriter
(
new
OutputStreamWriter
(
System
.
out
));
int
tests
=
Integer
.
parseInt
(
br
.
readLine
());
for
(
int
t
=
0
;
t
<
tests
;
t
++){
int
n
=
Integer
.
parseInt
(
br
.
readLine
());
int
num
[]=
new
int
[
n
];
String
[]
s
=
br
.
readLine
().
split
(
" "
);
for
(
int
i
=
0
;
i
<
n
;
i
++){
num
[
i
]=
Integer
.
parseInt
(
s
[
i
]);
}
ans
=
0
;
long
tempSum
=
0
;
/* //does not handle the case all array element are negative.
for(int i=0;i<n;i++){
tempSum=+num[i];
if(tempSum<0){
tempSum=0;
}
ans=Math.max(ans,temp);
}
*/
//handle the all negative case
ans
=-
100000000000L
;
for
(
int
i
=
0
;
i
<
n
;
i
++){
tempSum
=
Math
.
max
(
num
[
i
],
tempSum
+
num
[
i
]);
ans
=
Math
.
max
(
ans
,
tempSum
);
}
out
.
write
(
""
+
ans
+
"
\n
"
);
out
.
flush
();
}
}
}
Back
|
FazBrowse Home
|
New Git URL