-1
Write faster code
Your solution looks like it’s O(T \times D^2), and with D=1000 and T=200, this is going to be fairly tight in C++, and probably not possible with Python (the amount of time taken by a Python solution is immensely variable).
A O(T \times D) solution is possible, so aim for that.