From 0bb26e7e935f13e5eb963cf9fb72c288bd0f1ad3 Mon Sep 17 00:00:00 2001 From: tgyuuAn Date: Fri, 31 Jan 2025 15:39:06 +0900 Subject: [PATCH] 2025-01-31 --- tgyuuAn/README.md | 1 + .../\355\203\235\353\260\260.py" | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 "tgyuuAn/\352\267\270\353\246\254\353\224\224/\355\203\235\353\260\260.py" diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 6883eb7..2aa37f7 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -87,4 +87,5 @@ | 83차시 | 2024.12.01 | 수학 + 구현 | 칵테일 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/259 | 84차시 | 2024.12.31 | BFS | 불! | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/261 | 86차시 | 2025.01.16 | 이분 탐색 | 통나무 자르기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/265 +| 87차시 | 2025.01.31 | 그리디 | 택배 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/268 --- diff --git "a/tgyuuAn/\352\267\270\353\246\254\353\224\224/\355\203\235\353\260\260.py" "b/tgyuuAn/\352\267\270\353\246\254\353\224\224/\355\203\235\353\260\260.py" new file mode 100644 index 0000000..48ac4ec --- /dev/null +++ "b/tgyuuAn/\352\267\270\353\246\254\353\224\224/\355\203\235\353\260\260.py" @@ -0,0 +1,30 @@ +import sys + +def input(): return sys.stdin.readline().rstrip() + +N, C = map(int, input().split()) +M = int(input()) + +delieveries = [] +for _ in range(M): + start, destination, size = map(int, input().split()) + delieveries.append((start, destination, size)) + +delieveries.sort(key = lambda x : (x[1], x[0])) +table = [C for _ in range(N+1)] + +answer = 0 +previous_start = 0 +for delievery in delieveries: + start, destination, capacity = delievery + + can_delievery = capacity + for town in range(start, destination): + can_delievery = min(can_delievery, table[town]) + + for town in range(start, destination): + table[town] -= can_delievery + + answer += can_delievery + +print(answer) \ No newline at end of file