Cod sursa(job #2020037)
| Utilizator | Data | 9 septembrie 2017 12:29:00 | |
|---|---|---|---|
| Problema | Numarare triunghiuri | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.62 kb |
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin ("nrtri.in");
ofstream fout ("nrtri.out");
vector<int>v;
int main()
{
int n,x,nr=0,i;
fin>>n;
for(i=1;i<=n;i++)
{
fin>>x;
v.push_back(x);
}
sort(v.begin(),v.end());
vector<int>::iterator it1,it2,it3;
for(it1=v.begin();it1!=v.end()-2;it1++)
for(it2=it1+1;it2!=v.end()-1;it2++)
{
it3=upper_bound(it2+1,v.end(),((*it1)+(*it2)));
nr=nr+(int)(it3-it2-1);
}
fout<<nr;
fin.close();
fout.close();
return 0;
}
