Cod sursa(job #552692)

Utilizator feelshiftFeelshift feelshift Data 12 martie 2011 18:32:25
Problema Numarare triunghiuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
// http://infoarena.ro/problema/nrtri
#include <fstream>
#include <algorithm>
using namespace std;

#define maxSize 801
#define nrSticks length[0]

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

int answer;
int length[maxSize];

int main() {
	in >> nrSticks;
	for(int i=1;i<=nrSticks;i++)
		in >> length[i];

	sort(length+1,length+nrSticks+1);

	for(int a=1;a<=nrSticks-2;a++)
		for(int b=a+1;b<=nrSticks-1;b++) {
			int c = b + 1;

			while( (length[a] + length[b]) >= length[c] && c <= nrSticks)
				c++;

			answer += c - b - 1;
		}

	out << answer << "\n";

	in.close();
	out.close();

	return (0);
}