๋ฐ์ํ
๋ฌธ์ ๋งํฌ
https://www.acmicpc.net/problem/1912
๋ฌธ์ ํ์ด idea
์์์ ํ๋ dp ๋ฌธ์ ์ ๋ค๋ฅผ ๊ฒ ์๋ ๋ฌธ์ ! ์์์๋ถํฐ ๋ํด์ฃผ๊ณ max๊ฐ์ผ๋ก ๋ฐ๊ฟ์ฃผ๋ฉด ๋ผ. ์๋๋ฉด!! ์ด์ฐจํผ ๊ฐ์ฅ ํฐ ๊ฐ์ ์ฐพ๋๊ฑฐ๋ผ ๊ณ์ max ๊ฐ์ผ๋ก ์ ๋ฐ์ดํธ ๋๊ธฐ ๋๋ฌธ์ด๋ค.
์์ค์ฝ๋
let n = Int(String(readLine()!))!
let arr = readLine()!.split(separator: " ").map{Int(String($0))!}
var dp = Array(repeating: -1001, count: 100001)
dp[0] = arr[0]
for i in 1..<n{
dp[i] = max(arr[i],dp[i - 1] + arr[i])
}
print(dp.max()!)
๋ฐ์ํ