Pagini recente » Istoria paginii runda/abac | Cod sursa (job #872796) | Cod sursa (job #2160060) | Cod sursa (job #1680373) | Cod sursa (job #2644409)
#include <bits/stdc++.h>
using namespace std;
ifstream f("nrtri.in");
ofstream g("nrtri.out");
int n, i, j, v[1001], nr, m, dr, st;
int main()
{ f >> n;
for ( i=1; i<=n; i++ )
f >> v[i];
sort ( v+1, v+n+1 );
for ( i=1; i<n-1; i++ )
for ( j=i+1; j<n; j++ )
{
st = j + 1; dr = n;
while ( st <= dr )
{
m = ( st + dr )/2;
if ( v[i] + v[j] >= v[m] )
{
nr++; st = m + 1;
}
else dr = m - 1;
}
}
g << nr;
return 0;
}