From fa2fe224bb362a52bc78bfcb5438e9d3762506ae Mon Sep 17 00:00:00 2001 From: sh0723 Date: Wed, 27 May 2026 02:25:16 +0900 Subject: [PATCH] =?UTF-8?q?2828=20:=20=EC=82=AC=EA=B3=BC=20=EB=8B=B4?= =?UTF-8?q?=EA=B8=B0=20=EA=B2=8C=EC=9E=84=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week2/BOJ2828/BOJ2828_V1.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/week2/BOJ2828/BOJ2828_V1.cpp diff --git a/src/week2/BOJ2828/BOJ2828_V1.cpp b/src/week2/BOJ2828/BOJ2828_V1.cpp new file mode 100644 index 0000000..e8d1342 --- /dev/null +++ b/src/week2/BOJ2828/BOJ2828_V1.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; + +int main() { + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + int N, M; + cin >> N >> M; + + int j; + cin >> j; + int cur_pos = 1; + int dist_cnt = 0; + for (int i = 1; i <= j; i++) { + int position; + cin >> position; + if (position >= cur_pos && position <= cur_pos + M - 1) + continue; + + if (position < cur_pos) { + dist_cnt += (cur_pos - position); + cur_pos = position; + } else { + dist_cnt += (position - cur_pos - M + 1); + cur_pos = (position - M + 1); + } + } + + cout << dist_cnt << endl; +} \ No newline at end of file