NOTATRI TLE

how can i make this faster (i always get"time limit extended")…time limit is 2 sec…this is in pyth 3.1.2

import sys
n=int(sys.stdin.readline())

while(n!=0):

a=list(map(int,sys.stdin.readline().split()))
a.sort()
i=0;j=0;count=0
for i in range(n):
    for j in range(i+1,n):
        if a[i]+a[j]<a[n-1]:
            count+=1
print(count)
n=int(sys.stdin.readline())

USE BINARY SEARCH :slight_smile:

use Binary search or 2 pointers concept

1 Like