Cod sursa(job #924010)

Utilizator andreiblaj17Andrei Blaj andreiblaj17 Data 24 martie 2013 00:33:40
Problema Numarare triunghiuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#define nmax 805

using namespace std;

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

int n,v[nmax],k,hi,lo,mid;

void citire() {
    in >> n;
    for (int i=1; i<=n; i++) in >> v[i];
}

void sortare() {
    sort(v+1,v+n+1);
}

void hard_work() {
    for (int i=1; i<=n-2; i++)
        for (int j=i+1; j<=n-1; j++)
            for (int h=j+1; h<=n; h++){
                if (v[i]+v[j]>=v[h]) k++;
                else break;
            }
    out << k;
}

int main()
{
    citire();
    sortare();
    hard_work();

    return 0;
}