-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5642.cpp
More file actions
43 lines (39 loc) · 784 Bytes
/
5642.cpp
File metadata and controls
43 lines (39 loc) · 784 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
// 5642. 합
// 2019.07.05
#include<iostream>
#include<algorithm>
using namespace std;
int a[100001]; // 수들이 들어간 배열
int d[100001]; // d[i] : i번째 수까지의 연속합의 최댓값
int main()
{
int t;
cin >> t;
for (int test_case = 1; test_case <= t; test_case++)
{
int n;
int answer;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
d[1] = a[1];
for (int i = 2; i <= n; i++)
{
// (이전까지의 합 + 현재 값)과 (현재 값) 중 최댓값
d[i] = max(d[i - 1] + a[i], a[i]);
}
//d[1]을 포함한 모든 d[i] 값중 최댓값을 출력
answer = d[1];
for (int i = 2; i <= n; i++)
{
if (d[i] > answer)
{
answer = d[i];
}
}
cout << "#" << test_case << " " << answer << endl;
}
return 0;
}