๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm

[๋ฐฑ์ค€] 2455๋ฒˆ: ์ง€๋Šฅํ˜• ๊ธฐ์ฐจ

by ์ฃผ๋ฐœ2 2020. 5. 12.
๋ฐ˜์‘ํ˜•

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

 

2455๋ฒˆ: ์ง€๋Šฅํ˜• ๊ธฐ์ฐจ

์ตœ๊ทผ์— ๊ฐœ๋ฐœ๋œ ์ง€๋Šฅํ˜• ๊ธฐ์ฐจ๊ฐ€ 1๋ฒˆ์—ญ(์ถœ๋ฐœ์—ญ)๋ถ€ํ„ฐ 4๋ฒˆ์—ญ(์ข…์ฐฉ์—ญ)๊นŒ์ง€ 4๊ฐœ์˜ ์ •์ฐจ์—ญ์ด ์žˆ๋Š” ๋…ธ์„ ์—์„œ ์šดํ–‰๋˜๊ณ  ์žˆ๋‹ค. ์ด ๊ธฐ์ฐจ์—๋Š” ํƒ€๊ฑฐ๋‚˜ ๋‚ด๋ฆฌ๋Š” ์‚ฌ๋žŒ ์ˆ˜๋ฅผ ์ž๋™์œผ๋กœ ์ธ์‹ํ•  ์ˆ˜ ์žˆ๋Š” ์žฅ์น˜๊ฐ€ ์žˆ๋‹ค. ๏ฟฝ

www.acmicpc.net

์ฝ”๋“œ

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int people = 0;
		int max = -1;
		
		for(int i=0; i<4; i++) {
			int income = scan.nextInt();
			int outcome = scan.nextInt();
			
			people = people - income + outcome;
			max = Math.max(people, max);
		}
		
		System.out.println(max);
		scan.close();
	}

}

ํ’€์ด

๊ฐ ์—ญ์—์„œ ์‚ฌ๋žŒ์˜ ์ˆ˜๋ฅผ ๋น„๊ตํ•˜๋ฉด์„œ ํฐ ๊ฐ’์„ ์ฐพ๋Š”๋‹ค.

์‚ฌ๋žŒ์ˆ˜ = ์‚ฌ๋žŒ์ˆ˜ - ๋‚ด๋ฆฐ ์‚ฌ๋žŒ์ˆ˜ + ํƒ„ ์‚ฌ๋žŒ์ˆ˜

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€