ZeroRadish

[백준] 1912번 연속합(JAVA) 본문

카테고리 없음

[백준] 1912번 연속합(JAVA)

ZeroRadish Etc 2024. 8. 1. 09:09

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

 

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int max = Integer.MIN_VALUE, currentSum = 0;

        for (int i = 0; i < N; i++) {
            int num = scanner.nextInt();
            currentSum = Math.max(num, currentSum + num);
            max = Math.max(max, currentSum);
        }
        System.out.println(max);
    }
}
Comments