my code 169668033
getting TLE in test 2, have used fast_IO and verified this time complexity with solution solution blogalso.. have used same logic
what I am doing wrong here..
def remove(arr, ele):
arr.remove(ele)
return arr
t = int(input())
for _ in range(0, t):
n = int(input())
a = []
op = []
for i in range(1, n+1):
a.append(i)
# print(a)
for i in range(0, n-1):
# a.sort()
x = a[-1]
y = a[-2]
a.append(round( (x+y)/2) )
op.append([x,y])
a = remove(a, x)
a = remove(a, y)
sys.stdout.write(str(a[0]) + "\n")
for i in op:
sys.stdout.write(" ".join(map(str,i)) + "\n")
arr.remove(ele) is O(n) time not O(1) so your overall algorithm is O(n^2)
169678897 see this now I have removed arr.remove(ele) then too TLE in test 2
a = a[:-2]
is $$$O(n)$$$ time too.You should use
a.pop(); a.pop();
instead ofa = a[:-2]
.