From cc2af89f5ee97b18ab055046bb69248c73aa67b9 Mon Sep 17 00:00:00 2001 From: yenru0 Date: Mon, 5 Aug 2024 21:45:56 +0900 Subject: [PATCH] complete 10431.py --- zeta_python/completed/10431.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 zeta_python/completed/10431.py diff --git a/zeta_python/completed/10431.py b/zeta_python/completed/10431.py new file mode 100644 index 0000000..baa2330 --- /dev/null +++ b/zeta_python/completed/10431.py @@ -0,0 +1,28 @@ +import sys + +input = sys.stdin.readline + + +def solve(A: list[int]): + A.reverse() + B = [] + cnt = 0 + while A: + a = A.pop() + l = len(B) + for i, b in enumerate(B): + if b > a: + B.insert(i, a) + cnt += l - i + break + else: + B.append(a) + + return cnt + + +if __name__ == "__main__": + T = int(input()) + for _ in range(T): + t, *A = map(int, input().split()) + print(t, solve(A))