Pagini recente » Cod sursa (job #1892520) | Cod sursa (job #3272877) | Cod sursa (job #2517082) | Cod sursa (job #2206241) | Cod sursa (job #151627)
Cod sursa(job #151627)
#include<stdio.h>
#include<algorithm>
#define nmax 801
using namespace std;
int a[nmax];
int cauta(int st,int dr,int val)
{
int mij=(st+dr)/2;
if(a[mij]<=val && a[mij+1]>val)
return mij;
else
if(a[mij]>val)
return cauta(st,mij,val);
else
if(a[mij]<=val && a[mij+1]<=val)
return cauta(mij+1,dr,val);
}
int main()
{
freopen("nrtri.in","r",stdin);
freopen("nrtri.out","w",stdout);
int n,j;
int solfin=0,i;
scanf("%d",&n);
for(i=1; i<=n; ++i)
scanf("%d",&a[i]);
sort(a+1,a+1+n);
a[n+1]=a[n+2]=50000; //mult
int m=n-1,poz;
for(i=1; i<m; ++i)
for(j=i+1; j<=m; ++j){
poz=cauta(j,n,a[i]+a[j]);
if(poz!=j)
solfin+=poz-i-1;
}
printf("%d\n",solfin);
return 0;
}