Cod sursa(job #964656)

Utilizator poptibiPop Tiberiu poptibi Data 21 iunie 2013 21:15:37
Problema Oite Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <cstdio>
#include <cstdlib>
#include <map>
#include <algorithm>
using namespace std;

#define Nmax 1200

map<int, int> Hash;
int N, L, V[Nmax];
long long Ans;

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

    scanf("%i %i", &N, &L);
    for(int i = 1; i <= N; ++ i) scanf("%i", &V[i]);

    for(int i = 1; i <= N; ++ i)
    {
        for(int j = i + 1; j <= N; ++ j)
            if(Hash.count(L - V[i] - V[j]))
                Ans += 1LL * Hash[L - V[i] - V[j]];
        for(int j = 1; j < i; ++ j)
            Hash[V[i] + V[j]] ++;
    }
    printf("%i\n", Ans);
    return 0;
}