Cod sursa(job #419523)

Utilizator AndrewTheGreatAndrei Alexandrescu AndrewTheGreat Data 17 martie 2010 17:43:55
Problema Medie Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <iostream>

using namespace std;

struct vul
{
    int daca;
    int cat;
} numar[7010];

int v[9050],maxi;

int main()
{
    freopen ("medie.in","r",stdin);
    freopen ("medie.out","w",stdout);

    long long n,x;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        numar[v[i]].daca=1;
        numar[v[i]].cat++;
    }

    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++)
        {
            x=v[i]+v[j];
            if(x%2==0)
            {
                numar[v[i]].cat--;
                numar[v[j]].cat--;
                if(numar[x/2].daca)
                    maxi+=numar[x/2].cat;
                numar[v[i]].cat++;
                numar[v[j]].cat++;
            }
        }
    cout<<maxi;
    return 0;
}