Cod sursa(job #1220261)
Utilizator | Data | 16 august 2014 23:55:30 | |
---|---|---|---|
Problema | Numarare triunghiuri | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.41 kb |
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("nrtri.in");
ofstream g("nrtri.out");
int a[802],n,i,j,d,nr;
int main()
{
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
f.close();
sort(a+1,a+n+1);
for(i=1;i<=n-2;i++)
for(j=i+1;j<=n-1;j++)
for(d=j+1;d<=n && a[i]+a[j]>=a[d];d++)
nr++;
g<<nr;g.close();
return 0;
}