알고리즘/백준 등

[백준] 지능형기차2

컵라면만두세트 2021. 5. 2. 21:08

직관적으로 생각한 문제

package Solution;

import java.util.Scanner;

public class 지능형기차2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int sum =0; // 기차 안에 사람수
		int arr[] = new int[10];
		int result =0;
		
		arr[0] = sc.nextInt() + sc.nextInt(); // 처음
		
		for(int i =1; i<10; i++) {
			int a = sc.nextInt(); // 내린사람 
			int b = sc.nextInt(); // 탄사람 
			sum += b - a;
			arr[i] = sum + arr[i-1];
			sum =0;
		}
		
		for(int i=0; i<10; i++) {
			if(arr[i]>result)
				result = arr[i];
		}
		System.out.println(result);
	}

}

'알고리즘 > 백준 등' 카테고리의 다른 글

[백준] 경로찾기  (0) 2021.05.09
[백준] 꽃길  (0) 2021.05.09
[백준] 오르막길  (0) 2021.05.02
[백준] 토마토7576  (0) 2021.04.23
[백준] 경비원  (0) 2021.04.14