Following is my code to the problem [Link](https://mirror.codeforces.com/contest/777/problem/C)↵
↵
~~~~~↵
I=lambda:[*map(int,input().split())]↵
rr=range↵
n,m=I()↵
a=[I() for _ in rr(n)]↵
# print(a)↵
dp=[0]*(n+1)↵
for i in rr(m):↵
st=en=0↵
for j in rr(1,n):↵
if a[j-1][i]>a[j][i]:↵
dp[st+1]=max(dp[st+1],en+1)↵
st=en=j↵
else :↵
en+=1↵
dp[st+1]=max(dp[st+1],en+1)↵
for i in rr(1,n+1):↵
dp[i]=max(dp[i],dp[i-1])↵
↵
q,=I()↵
for i in rr(q):↵
x,y=I()↵
print('Yes' if dp[x]>=y else 'No')↵
~~~~~↵
![ ](/predownloaded/38/73/3873c4711d8a26ba96420bd8112ef75321616b5a.png)↵
↵
↵
It gives TLE in some submissions while passes in others, to the fact that all have same code.↵
Also sometimes for the same code Python 3 throws TLE and sometimes PyPy3. ↵
Is there any way to overcome this uncertainty,↵
Or can anyone pls give reason for this↵
↵
~~~~~↵
I=lambda:[*map(int,input().split())]↵
rr=range↵
n,m=I()↵
a=[I() for _ in rr(n)]↵
# print(a)↵
dp=[0]*(n+1)↵
for i in rr(m):↵
st=en=0↵
for j in rr(1,n):↵
if a[j-1][i]>a[j][i]:↵
dp[st+1]=max(dp[st+1],en+1)↵
st=en=j↵
else :↵
en+=1↵
dp[st+1]=max(dp[st+1],en+1)↵
for i in rr(1,n+1):↵
dp[i]=max(dp[i],dp[i-1])↵
↵
q,=I()↵
for i in rr(q):↵
x,y=I()↵
print('Yes' if dp[x]>=y else 'No')↵
~~~~~↵
![ ](/predownloaded/38/73/3873c4711d8a26ba96420bd8112ef75321616b5a.png)↵
↵
↵
It gives TLE in some submissions while passes in others, to the fact that all have same code.↵
Also sometimes for the same code Python 3 throws TLE and sometimes PyPy3. ↵
Is there any way to overcome this uncertainty,↵
Or can anyone pls give reason for this↵