more on a2p3

This commit is contained in:
0x01FE 2025-02-06 12:17:03 -06:00
parent 156b2eaa64
commit dea42ea39c
3 changed files with 94 additions and 0 deletions

View File

@ -0,0 +1,54 @@
def partition(arr: list, low: int, high: int) -> int:
pivot = arr[high]
i = low - 1
for j in range(low, high):
if arr[j] < pivot:
i += 1
swap(arr, i, j)
swap(arr, i + 1, high)
return i + 1
def swap(arr: list, i: int, j: int) -> None:
arr[i], arr[j] = arr[j], arr[i]
def quick_sort_h(arr: list, low: int, high: int) -> list:
# copy = arr.copy()
if low < high:
pi = partition(arr, low, high)
quick_sort_h(arr, low, pi - 1)
quick_sort_h(arr, pi + 1, high)
# return copy
# def quick_sort(arr: list) -> list:
# return quick_sort_h(arr, 0, len(arr) - 1)
def main():
lines: list[str] = []
test_cases = int(input())
while (test_cases != 0):
n = int(input())
while (n != 0):
lines.append(input())
n -= 1
quick_sort_h(lines, 0, len(lines) - 1)
for line in lines:
print(line)
lines = []
test_cases -= 1
if __name__ == "__main__":
main()

40
MAIN8_C/MAIN8_C.py Normal file
View File

@ -0,0 +1,40 @@
def main():
test_cases = int(input())
while (test_cases != 0):
n, k = [int(n) for n in input().split()]
boxes: list[int] = [int(candies) for candies in input().split()]
boxes.sort(reverse=True)
# k = 2
# [4, 3, 1]
i = 0
l = len(boxes)
largest = boxes[i]
while largest > 0:
correct = 0
for candies in boxes:
if (c := candies // largest) > 0:
correct += c
if correct >= k:
break
i += 1
if i >= l:
largest = 0
break
largest = boxes[i]
print(largest)
test_cases -= 1
if __name__ == "__main__":
main()