※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 26432번 문제인 Walktober이다.
문제는 아래 링크를 확인하자.

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

 

26432번: Walktober

In the Sample Case, the competition ran for $3$ days and the participant ID of John was $1$. On day $1$, as the other participant has more steps, John needs $500$ additional steps. On the rest of the days, as John already has the maximum steps, he needs no

www.acmicpc.net

구하려는 문제의 답은 각 대회날짜 n에 대하여 (n번째 날에 부족하게 걸었던 걸음 수)를 모두 합해 계산할 수 있다. 이 값은 (n번째 날에 가장 많이 걸은 사람의 걸음 수) - (n번째 날에 John이 걸은 걸음 수)의 최댓값들을 합하는 것으로 계산할 수 있다.

 

이차원 배열에 주어지는 데이터를 입력받고 반복문을 이용해 위의 값을 계산해 합하는 것으로 문제를 해결하자.

 

아래는 제출한 소스코드이다.

#include <iostream>
using namespace std;

int T;
int M, N, P;
int arr[1001][32];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> T;
	for (int t = 1; t <= T; t++) {
		int ans = 0;
		cin >> M >> N >> P;
		for (int m = 1; m <= M; m++) {
			for (int n = 1; n <= N; n++) {
				cin >> arr[m][n];
			}
		}
		for (int n = 1; n <= N; n++) {
			int tmp = 0;
			for (int m = 1; m <= M; m++) tmp = max(tmp, arr[m][n] - arr[P][n]);
			ans += tmp;
		}
		cout << "Case #" << t << ": " << ans << '\n';
	}
}
728x90

'BOJ' 카테고리의 다른 글

[BOJ 25376 // C++] 이상한 스위치  (0) 2023.01.24
[BOJ 25374 // C++] 등급 계산하기  (0) 2023.01.23
[BOJ 27268 // C++] Рамки  (0) 2023.01.23
[BOJ 25204 // C++] 문자열 정렬  (0) 2023.01.22
[BOJ 23327 // C++] 리그전 오브 레전드  (0) 2023.01.22

+ Recent posts