Cod sursa(job #1327155)

Utilizator pepsiM4A1Ozturk Arif pepsiM4A1 Data 26 ianuarie 2015 13:55:39
Problema Numarare triunghiuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <stdio.h>
#include <algorithm>
int n;
int a[801];
int main()
{
    freopen ("nrtri.in","r",stdin);
    freopen ("nrtri.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    std::sort(a+1,a+n+1);
    int sum,count=0;
    for(int i=1;i<n;i++)
    {
            for(int j=i+1;j<=n;j++)
            {
                    sum=a[i]+a[j];
                    for(int k=j+1;k<=n;k++)
                    {
                            if(sum>=a[k]) count++;
                            else break;
                    }
            }
    }
    printf("%d\n",count);
}