AtCoder Beginner Contest 143 D - Triangles【Python】
https://atcoder.jp/contests/abc143/tasks/abc143_d
AtCoder ProblemsのRecommendationでDifficulty: 686、Solve Probability:
37%でした。
aとbを固定してcの個数を二分探索で求めました。
import bisect N = int(input()) L = list(map(int, input().split())) L = sorted(L) ans = 0 for i in range(N-2): for j in range(i+1, N-1): a = L[i] b = L[j] lower = bisect.bisect_left(L[j+1:], b - a) upper = bisect.bisect_left(L[j+1:], a + b) ans += upper - lower print(ans)