Cod sursa(job #660023)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 11 ianuarie 2012 16:44:51
Problema Numarare triunghiuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <cstdio>
#include <algorithm>

#define NMax 805
#define LMax 64000

using namespace std;

int N, L[NMax], S;

void Read ()
{
    freopen ("nrtri.in", "r", stdin);
    scanf ("%d", &N);
    for (int i=1; i<=N; ++i)
    {
        scanf ("%d", &L[i]);
    }
}

void Print ()
{
    freopen ("nrtri.out", "w", stdout);
    printf ("%d\n", S);
}

void Solve ()
{
    sort (L+1, L+N+1);
    for (int i=1; i<=N; ++i)
    {
        for (int j=i+1; j<=N; ++j)
        {
            S+=(upper_bound (L+j+1, L+N+1, L[i]+L[j])-(L+j+1));
        }
    }
}

int main()
{
    Read ();
    Solve ();
    Print ();
    return 0;
}