[BOJ][C#] 1912 연속합

LimJaeJun·2023년 7월 30일

PS/BOJ

목록 보기
1/108

📕 문제

📌 링크
문제 사진1

📘 코드

namespace BOJ
{
    class No_1912
    {
        static void Main()
        {
            using StreamReader input = new StreamReader(new BufferedStream(Console.OpenStandardInput()));
            using StreamWriter output = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()));

            int n = int.Parse(input.ReadLine());
            int[] arr = Array.ConvertAll(input.ReadLine().Split(), int.Parse);

            int[] dp = new int[arr.Length];

            dp[0] = arr[0];
            int answer = arr[0];

            for (int i=1 ;i<dp.Length ;i++)
            {
                dp[i] = Math.Max(dp[i - 1] + arr[i], arr[i]);
                answer = Math.Max(answer, dp[i]);
            }

            output.WriteLine(answer);
        }
    }
}

📙 오답노트

📒 알고리즘 분류

  • 다이나믹 프로그래밍
profile
Dreams Come True

0개의 댓글