[20251101] BOJ / G5 / 태상이의 훈련소 생활 / 이준희 #1286
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/19951
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
훈련소 첫날부터 가스조절기를 잃어버린 태상이에게
N개의 수(높이)로 이루어진 땅을 메꾸거나 파는 징계가 주어졌을 때
모든 작업 이후 땅의 높이를 구하는 문제입니다.
이 때 각 작업은 a, b, k 로 주어지는데 a 부터 b까지 k만큼 파거나 메꾸는 행위입니다.
🔍 풀이 방법
누적합을 이용해서 풀었습니다. k를 이용하여 n크기의 차이배열을 만들었습니다.
이 때 a, b, k 가 주어지면 a에서는 k만큼 더하고 b+1 에서는 k만큼 빼게 됩니다.
그러면 [k, 0, 0, -k] 이런식으로 되서 b+1 에서는 결국 누적합이 0이 되므로 정답을 도출할 수있습니다.
⏳ 회고
태상이는 폐급입니다