Pagini recente » Cod sursa (job #1921664) | Istoria paginii runda/id | Cod sursa (job #2010868) | Cod sursa (job #2032063) | Cod sursa (job #1444263)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int a[9005];
int main()
{
ifstream in("medie.in");
ofstream out("medie.out");
int i, n, j, x, y, mij, tot = 0,z;
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 = 1; j <= n; j++)
{
if (j == i){ continue; }
x = j+1;
y = n;
while (x <= y)
{
mij = (x + y) / 2;
if (a[mij] + a[j] == 2*a[i])
{
z = mij-1;
while (a[mij] == a[z]&&z>j)
{
tot++;
if (z == j || z == i){ tot--; }
z--;
}
z = mij + 1;
while (a[mij] == a[z])
{
tot++;
if (z == j || z == i){ tot--; }
z++;
}
if (mij!=j&&mij!=i)
tot++;
x = y + 1;
}
else if ((a[mij] + a[j]) < 2*a[i])
{
x = mij + 1;
}
else
{
y = mij - 1;
}
}
}
}
out << tot;
}