Cod sursa(job #1653252)

Utilizator Vasile_RotaruVasea Rotaru Vasile_Rotaru Data 15 martie 2016 20:29:04
Problema Numarare triunghiuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.36 kb
#include<fstream>
#include<algorithm>
using namespace std;

ifstream fin("nrtri.in");
ofstream fout("nrtri.out");

int n,i,j,k,a[801],m=0;



int main()
{
	fin>>n;
	for(i=1;i<=n;++i)
		fin>>a[i];
	sort(a+1,a+n+1);
	for(i=1;i<=n;++i)
	for(j=i+1;j<=n;++j)
	{
		k=j+1;
		while(a[i]+a[j]>=a[k] && k<=n)++k;
		m+=k-j-1;
	}
	fout<<m;
 	return 0;
}