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