Cod sursa(job #37078)

Utilizator nimicLeoveanu Mihaita Alexandru nimic Data 24 martie 2007 16:32:39
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <stdio.h>
#include <ext/hash_map>
#include <algorithm>
#include <map>
#define baga(k) h[(k)%MOD].push_back(k);

using namespace std;
using namespace __gnu_cxx; 

int n, sol;
unsigned s, a[1200];
hash_map <unsigned, unsigned> nr;

int main()
{
    freopen("oite.in", "r", stdin);
    freopen("oite.out", "w", stdout);
    scanf("%d %u", &n, &s);
    int i,k;
    for (i=0; i<n; i++)
        scanf("%u", a+i);
    sort(a, a+n);
    for (k=2; k<n-1; k++){
        for (i=0; i<k-1; i++)
            nr[a[k-1]+a[i]]++;
        for (i=k+1; i<n; i++)
            sol+=nr[s-a[k]-a[i]];
    }
    printf("%d\n", sol);
    return 0;
}