Cod sursa(job #1527485)

Utilizator MatteusTanase Matei Matteus Data 18 noiembrie 2015 10:04:35
Problema Numarare triunghiuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("nrtri.in");
ofstream cout("nrtri.out");
int v[801];
int main()
{
    int n,i,s,c=0,j,k;
    cin>>n;
    for(i=1; i<=n; i++)
        cin>>v[i];
    sort(v+1, v+n+1);
    for(i=1; i+2<=n; i++)
    {
        k=1;
        for(j=i+1; j+1<=n; j++)
        {
            while(k<=n && v[i]+v[j]>=v[k])
                k++;
            if(k>j)
                c+=k-j-1;
        }
    }

    cout<<c;
    return 0;
}