diff --git a/LEXISORT/main.py b/LEXISORT/LEXISORT-MERGE.py similarity index 100% rename from LEXISORT/main.py rename to LEXISORT/LEXISORT-MERGE.py diff --git a/LEXISORT/LEXISORT-QUICK.py b/LEXISORT/LEXISORT-QUICK.py new file mode 100644 index 0000000..6767f56 --- /dev/null +++ b/LEXISORT/LEXISORT-QUICK.py @@ -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() \ No newline at end of file diff --git a/MAIN8_C/MAIN8_C.py b/MAIN8_C/MAIN8_C.py new file mode 100644 index 0000000..435b124 --- /dev/null +++ b/MAIN8_C/MAIN8_C.py @@ -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() +