Cod sursa(job #938504)

Utilizator blasterzMircea Dima blasterz Data 12 aprilie 2013 19:22:34
Problema Numarare triunghiuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
#include <algorithm>
using namespace std;
const char iname[] = "nrtri.in";
const char oname[] = "nrtri.out";
ifstream fin(iname);
ofstream fout(oname);
int N, i, j, k, ANS, x, last_poz;
int v[804];
int main()
{
    fin >> N;
    for (i = 1; i <= N; ++i) fin >> v[i];
    sort (v + 1, v + N + 1);
    last_poz = 2;
    for (i = 1; i <= N; ++i)
    {
        for (j = i + 1; j <= N; ++j)
        {
            x = v[i] + v[j];
            for (k = last_poz; k <= N; ++k) if (v[k] <= x) last_poz = k;
            ANS += (last_poz - j);
        }
    }
    fout << ANS << '\n';
    return 0;
}