forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswe5642.java
More file actions
67 lines (46 loc) · 1.29 KB
/
swe5642.java
File metadata and controls
67 lines (46 loc) · 1.29 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class swe5642 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int idx = 1;
int T = sc.nextInt();
ArrayList<Integer> AL = new ArrayList<>();
//테스트케이스
for(int t=0; t<T; t++) {
int N = sc.nextInt();
//리스트에 값받기
for (int i = 0; i < N; i++) {
AL.add(sc.nextInt());
}
//리스트를 배열로
int[] A = new int[AL.size()];
for(int i=0; i<A.length; i++)
{
A[i] = AL.get(i);
}
int answer = MakeDp(A);
System.out.println("#"+ (idx++) + " " + answer);
AL.clear();
}
}
public static int MakeDp(int[] Array)
{
int max = -9999;
for(int i =1; i<Array.length; i++)
{
if(Array[i-1] > 0 && (Array[i] + Array[i-1]) > 0)
{
Array[i] += Array[i-1];
}
if(Array[i] > max)
max = Array[i];
}
//예외
if(Array[0] > max)
max = Array[0];
return max;
}
}