BOJ[백준] - 1912 - 연속합

Posted by ceyx
2017. 7. 15. 01:48 Algorithm 문제풀이/BOJ [백준] 문제풀이

https://www.acmicpc.net/problem/1912

 

 

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdio>
 
const int MXN = 100000;
int a[MXN+1], dp[MXN+1];
int main()
{
   int n;
   scanf("%d"&n);
   for (int i = 1; i <= n; i++)
   {
      scanf("%d"&a[i]);
      if(a[i] <= dp[i - 1+ a[i])
         dp[i] = dp[i - 1+ a[i];
      else
         dp[i] = a[i];
   }
   int max = -1001;
   for (int i = 1; i <= n; i++)
      max = (max < dp[i] ? dp[i] : max);
 
   printf("%d", max);
   return 0;
}
cs