more on a2p3
This commit is contained in:
parent
156b2eaa64
commit
dea42ea39c
54
LEXISORT/LEXISORT-QUICK.py
Normal file
54
LEXISORT/LEXISORT-QUICK.py
Normal 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
40
MAIN8_C/MAIN8_C.py
Normal 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()
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user