Cod sursa(job #2072449)

Utilizator Andrei_RAndrei Roceanu Andrei_R Data 21 noiembrie 2017 21:05:04
Problema Numarare triunghiuri Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

ifstream f("ntri.in");
ofstream g("ntri.out");

int v[802];

int main( ) {
    int n, i, j, p, s;
    f >> n;
    for( i = 0; i < n; i++ )
        f >> v[i];
    sort( v, v + n );
    s = 0;
    for( i = 0; i < n - 2; i++ ) {
        p = i + 2;
        for( j = i + 1; j < n - 1; j++ ) {
            if( j == p )
                p++;
            while( p < n && v[i] + v[j] >= v[p] )
                p++;
            s += p - j - 1;
            cout << s << " " << i << " " << j << " " << p << endl;
        }
    }
    g << s;
    g.close();
    f.close();
    return 0;
}