From 33214d1736664c87bc99509f6363c1660d9a3d06 Mon Sep 17 00:00:00 2001 From: yenru0 Date: Tue, 12 Mar 2024 00:39:49 +0900 Subject: [PATCH] aloha greedy1 --- zeta_python/11509.py | 17 +++++++++++++++++ zeta_python/completed/11501.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 zeta_python/11509.py create mode 100644 zeta_python/completed/11501.py diff --git a/zeta_python/11509.py b/zeta_python/11509.py new file mode 100644 index 0000000..577a78a --- /dev/null +++ b/zeta_python/11509.py @@ -0,0 +1,17 @@ +def solve(N, H): + lasts = [] + for i, h in enumerate(H): + for j, l in enumerate(lasts): + if h == l - 1: + lasts[j] -= 1 + break + else: + lasts.append(h) + + return len(lasts) + + +if __name__ == '__main__': + N = int(input()) + H = list(map(int, input().split())) + print(solve(N, H)) diff --git a/zeta_python/completed/11501.py b/zeta_python/completed/11501.py new file mode 100644 index 0000000..3c5440b --- /dev/null +++ b/zeta_python/completed/11501.py @@ -0,0 +1,29 @@ +def solve(N, P): + s = 0 + r, a = partition(P) + s += a + while (r): + r, a = partition(r) + s += a + return s + + +def partition(part: list): + max_p = max(part) + + m_idx = 0 + for i in range(len(part)): + if part[i] == max_p: + m_idx = i + remain = part[m_idx + 1:] + after = part[:m_idx] + amount = sum([max_p - v for v in after]) + return remain, amount + + +if __name__ == '__main__': + T = int(input()) + for _ in range(T): + N = int(input()) + P = list(map(int, input().split())) + print(solve(N, P))