From 5c2c5460bebc69b70bcdafe992547862cf7db6e8 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Fri, 7 Jun 2024 15:45:07 +0900 Subject: [PATCH] 2024-06-07 --- H0ngJu/README.md | 2 ++ ...5 \354\234\240\354\271\230\354\233\220.py" | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 "H0ngJu/\352\267\270\353\246\254\353\224\224/\355\226\211\353\263\265 \354\234\240\354\271\230\354\233\220.py" diff --git a/H0ngJu/README.md b/H0ngJu/README.md index df71f8e0..17c23417 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -22,4 +22,6 @@ | 18차시 | 2024.05.26 | DFS | [계란으로 계란치기](https://www.acmicpc.net/problem/16987) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/199 | | 19차시 | 2024.05.31 | DP | [합분해](https://www.acmicpc.net/problem/2225) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/202 | +| 21차시 | 2024.06.07 | 그리디 | [행복 유치원](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 | + --- diff --git "a/H0ngJu/\352\267\270\353\246\254\353\224\224/\355\226\211\353\263\265 \354\234\240\354\271\230\354\233\220.py" "b/H0ngJu/\352\267\270\353\246\254\353\224\224/\355\226\211\353\263\265 \354\234\240\354\271\230\354\233\220.py" new file mode 100644 index 00000000..4f4da00f --- /dev/null +++ "b/H0ngJu/\352\267\270\353\246\254\353\224\224/\355\226\211\353\263\265 \354\234\240\354\271\230\354\233\220.py" @@ -0,0 +1,19 @@ +import sys + +def input(): return sys.stdin.readline().rstrip() + +N, K = map(int, input().split()) +data = list(map(int, input().split())) +diff = [0] * N + +for i in range(N-1): + diff[i] = data[i+1] - data[i] + +diff.sort(reverse=True) + +total_diff = sum(diff) + +for i in range(K-1): + total_diff -= diff[i] + +print(total_diff) \ No newline at end of file