From 86ff42e88901a365491de8bf78931f7835789eb3 Mon Sep 17 00:00:00 2001 From: yenru0 Date: Mon, 15 Jul 2024 23:44:56 +0900 Subject: [PATCH] complete 2828.c --- zeta_C/completed/2828.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 zeta_C/completed/2828.c diff --git a/zeta_C/completed/2828.c b/zeta_C/completed/2828.c new file mode 100644 index 0000000..896700a --- /dev/null +++ b/zeta_C/completed/2828.c @@ -0,0 +1,27 @@ +#include +#include + +int main() { + int N, M, J, cnt = 0, tmp, now = 1, flag; + scanf("%d %d", &N, &M); + scanf("%d", &J); + int *pos = (int *) calloc(J, sizeof(int)); + for (int i = 0; i < J; i++) { + scanf("%d", pos + i); + } + for (int i = 0; i < J; i++) { + flag = 1; + while (flag) { + if (now <= pos[i] && pos[i] <= now + M - 1) { + flag = 0; + } else if (now > pos[i]) { + now--; + cnt++; + } else { + now++; + cnt++; + } + } + } + printf("%d\n", cnt); +} \ No newline at end of file