Что поправить в коде, чтоб он проходил по времени. Вот условие задачи:
You are given an array of n numbers and q queries. For each query you have to print the floor of the expected value(mean) of the subarray from L to R. Input: First line contains two integers N and Q denoting number of array elements and number of queries. Next line contains N space seperated integers denoting array elements. Next Q lines contain two integers L and R(indices of the array). Output: print a > single integer denoting the answer. Constraints: 1<= N ,Q,L,R <= 10^6 1<= Array elements <= 10^9 *
Вот мое решение:
N, Q = map(int, input().split())
array = list(map(int, input().split()))
for i in range(Q):
L, R = map(int, input().split())
print((sum(array[:R]) - sum(array[:L-1])) // (R - L + 1))
array[:R]
иarray[:L-1]
каждый раз делают копию части списка. Попробуйте использовать itertools.islice.