[백준] 2460번

park jinwoo·2023년 1월 10일
0

백준

목록 보기
91/94

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

10개의 역에 대해 기차에서 내린 사람 수와 탄 사람 수가 주어졌을 때, 기차에 사람이 가장 많을 때의 사람 수를 계산하는 프로그램을 작성하시오.

<script>
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int in, out, result = 0, max = 0;

	for (int i = 0; i < 10; i++) {
		scanf("%d %d", &out, &in);
		result -= out;
		result += in;
		if (result > max) {
			max = result;
		}
	// result에 out을 빼고 in을 더하고 max와 비교하는 for문
	}

	printf("%d", max);

	return 0;
}
</script>

0개의 댓글