52 lines
1.0 KiB
C++
52 lines
1.0 KiB
C++
#include <iostream>
|
|
#include <algorithm>
|
|
|
|
using namespace std;
|
|
|
|
int main()
|
|
{
|
|
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
|
|
|
|
int n;
|
|
cin >> n;
|
|
|
|
int a[n];
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
cin >> a[i];
|
|
}
|
|
sort(a, a + n);
|
|
// int index[1005]{};
|
|
// for(int i = 0; i < n; i++){
|
|
// cout << a[i] << " ";
|
|
// }
|
|
|
|
int cnt = 0;
|
|
for (int i1 = 0; i1 < n - 2; i1++)
|
|
{
|
|
int last = 0;
|
|
for (int i2 = i1 + 1; i2 < n - 1; i2++)
|
|
{
|
|
bool flag = false;
|
|
for (int i3 = max(i2 + 1, last); i3 < n; i3++)
|
|
{
|
|
if (a[i1] + a[i2] <= a[i3])
|
|
{
|
|
break;
|
|
}
|
|
if (a[i2] + a[i3] > a[i1] && a[i1] + a[i3] > a[i2])
|
|
{
|
|
if (!flag)
|
|
{
|
|
last = i3;
|
|
flag = true;
|
|
}
|
|
|
|
cnt++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
cout << cnt;
|
|
} |