Given an array A of N integers we draw N discs in a 2D plane, such that i-th disc has center in (0,i) and a radius
A
N
(0,i)
count = 0 for (int i = 0; i < N; i++) { for (int j = i+1; j < N; j++) { if (i + A[i] >= j - A[j]) count++; } }
It is O(N^2) so pretty slow, but it works.
O(N^2)