Cod sursa(job #1494259)

Utilizator ialexia_ioanaAlexia Ichim ialexia_ioana Data 30 septembrie 2015 21:21:30
Problema Numarare triunghiuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <cstdio>
#include <algorithm>
using namespace std ;
int v[805];
int main()
{
    freopen("nrtri.in" , "r" , stdin);
    freopen("nrtri.out" , "w" , stdout);
    int n, i, j, last, sol=0;
    scanf("%d" , &n);
    for(i=1; i<=n; i++)
        scanf("%d", &v[i]);
    sort(v+1, v+n+1) ;
    for (i=1; i<=n; i++)
    {
        last=i+1;
        for (j=i+1; j<=n ; j++)
        {
            while(last<j)
                last++;
            while(last<n && v[i]+v[j]>=v[last+1])
                last++;
            sol+=last-j;
        }
    }

    printf("%d\n" , sol);
    return 0;
}