/***********
Author Smile
https://vjudge.csgrandeur.cn/contest/477149#problem/G
***********/
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 2e3 + 10;
int n;
int w[N];
bool cmp(int a, int b)
{
return a > b;
}
void print()
{
for (int i = 1; i <= n; ++i)
cout << w[i] << ' ';
cout << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> w[i];
}
int l, r, mid;
int ans = 0;
sort(w + 1, w + 1 + n, cmp);
// print();
for (int i = 1; i <= n - 2; ++i)
{
for (int j = i + 1; j <= n - 1; ++j)
{
l = j + 1;
r = n;
while (l <= r)
{
mid = (l + r) / 2;
if (w[i] < w[j] + w[mid])
{
ans += mid - l + 1;
l = mid + 1;
}
else
r = mid - 1;
}
}
}
cout << ans << endl;
return 0;
}
08-08
350
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-30
290
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)