[BOJ] 1912 연속합

Time Lapse :NONE

1912.c

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
#include <iostream>
#include <algorithm>
using namespace std;

int N;
long long ans;
long long arr[100010];

int main(void) {

cin>>N;

for(int i=1;i<=N;i++)
cin>>arr[i];

arr[0]=0;
ans = arr[1];
for(int i=1;i<=N;i++)
{
arr[i]=max(arr[i],arr[i-1]+arr[i]);
ans = max(ans,arr[i]);
}
cout<<ans<<endl;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/1912/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.