Cod sursa(job #3200153)
Utilizator | radu pipernea radu_pip | Data | 3 februarie 2024 17:46:00 |
---|---|---|---|
Problema | Numarare triunghiuri | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.7 kb |
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("nrtri.in");
ofstream cout("nrtri.out");
int v[1000];
int main()
{
int n,cnt=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>v[i];
}
sort(v+1,v+n+1);
for(int i=1;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
int sum=v[i]+v[j];
int pas=j;
int pow=1;
while(pow<=n-j)
pow*=2;
pow/=2;
while(pow)
{
if(v[pas+pow] <=sum && pas+pow<=n)
pas+=pow;
pow/=2;
}
cnt+=pas-j;
}
}
cout<<cnt;
return 0;
}