Pagini recente » Cod sursa (job #2132182) | Cod sursa (job #1476088) | Cod sursa (job #1476715) | Cod sursa (job #3199276) | Cod sursa (job #2123762)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("nrtri.in");
ofstream g("nrtri.out");
int n,i,j,v[805],st,dr,mij,nr;
int main()
{
f>>n;
for(i=1; i<=n; i++)
{
f>>v[i];
}
sort(v+1,v+n+1);
for(i=1; i<=n-2; i++)
for(j=i+1; j<=n-1; j++)
{
st=j+1;
dr=n;
while(st<=dr)
{
mij=(st+dr)/2;
if(v[mij]<=v[i]+v[j])
st=mij+1;
else
dr=mij-1;
}
nr=nr+dr-j;
}
g<<nr;
return 0;
}