Pagini recente » Cod sursa (job #1090413) | Monitorul de evaluare | Cod sursa (job #1409649) | Cod sursa (job #535966) | Cod sursa (job #1431016)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int a[801];
int main()
{
ifstream in("nrtri.in");
ofstream out("nrtri.out");
int i, n,j,x,y,mij,maxim,tot=0;
in >> n;
for (i = 1;i <= n;i++)
{
in >> a[i];
}
sort(a + 1, a + n + 1);
for (i = 1;i <= n;i++)
{
for (j = i + 1;j < n;j++)
{
x = j + 1;
y = n;
maxim = 0;
while (x <= y)
{
mij = (x + y) / 2;
if (a[mij] <= a[i] + a[j])
{
maxim = mij;
x = mij + 1;
}
else
{
y = mij - 1;
}
}
if (maxim != 0)
{
tot += maxim - j;
}
}
}
out << tot;
}