Untitled

mail@pastecode.io avatar
unknown
python
7 months ago
1.6 kB
49
Indexable
Never
def merge_and_count(arr, left, mid, right):

    i, j = left, mid + 1

    count = 0
    merged = []

    while i <= mid and j <= right:
        if arr[i] <= arr[j]:
            merged.append(arr[i])
            i += 1
        else:
            merged.append(arr[j])
            count += (mid - i + 1)
            j += 1

    while i <= mid:
        merged.append(arr[i])
        i += 1

    while j <= right:
        merged.append(arr[j])
        j += 1

    arr[left:right + 1] = merged
    return count

def merge_sort_and_count(arr, left, right):
    if left < right:
        mid = (left + right) // 2
        left_count = merge_sort_and_count(arr, left, mid)
        right_count = merge_sort_and_count(arr, mid + 1, right)
        merge_count = merge_and_count(arr, left, mid, right)
        return left_count + right_count + merge_count
    return 0

def count_points(robert_numbers, rachel_numbers):
    total_numbers = robert_numbers + rachel_numbers
    merge_sort_and_count(total_numbers, 0, len(total_numbers) - 1)

    robert_score = merge_sort_and_count(robert_numbers, 0, len(robert_numbers) - 1)
    rachel_score = merge_sort_and_count(rachel_numbers, 0, len(rachel_numbers) - 1)

    return robert_score, rachel_score

if __name__ == "__main__":
    robert_numbers = list(map(int, input().split()))
    rachel_numbers = list(map(int, input().split()))

    robert_score, rachel_score = count_points(robert_numbers, rachel_numbers)

    print(rachel_score, robert_score)  # Rachel's score first, then Robert's score