aloha greedy1
This commit is contained in:
17
zeta_python/11509.py
Normal file
17
zeta_python/11509.py
Normal file
@@ -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))
|
||||||
29
zeta_python/completed/11501.py
Normal file
29
zeta_python/completed/11501.py
Normal file
@@ -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))
|
||||||
Reference in New Issue
Block a user