Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a07994
commit 53c9e95
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
32 changes: 32 additions & 0 deletions
32
CodingTestStudy1.0/src/DynamicProgramming/Problem1912.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package DynamicProgramming; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class Problem1912 { | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer str; | ||
|
||
int N = Integer.parseInt(br.readLine()); | ||
int[] arr = new int[N]; | ||
int[] dp = new int[N]; | ||
|
||
str = new StringTokenizer(br.readLine()); | ||
|
||
for (int i=0; i<N; i++) { | ||
arr[i] = Integer.parseInt(str.nextToken()); | ||
} | ||
|
||
dp[0] = arr[0]; | ||
int result = dp[0]; | ||
|
||
for (int i=1; i<N; i++) { | ||
dp[i] = Math.max(dp[i-1] + arr[i], arr[i]); | ||
if (result < dp[i]) result = dp[i]; | ||
} | ||
|
||
System.out.println(result); | ||
} | ||
} |