Cod sursa(job #58277)

Utilizator cos_minBondane Cosmin cos_min Data 4 mai 2007 22:32:01
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <stdio.h>
#include <ext/hash_map>
#include <vector>
using namespace std;

#define in "oite.in"
#define out "oite.out"
#define dim 1025
using namespace __gnu_cxx;

int N, L, total=0;
vector<unsigned> V;
hash_map<unsigned,unsigned> M;

int main()
{
    freopen(in,"r",stdin);
    freopen(out,"w",stdout);
    
    scanf("%d%d", &N, &L);
    V.resize(N+1);
    for ( int i = 1; i <= N; i++ )
    {
        scanf("%u", &V[i]);
    }
    
    sort(V.begin()+1,V.end());
    
    for ( int i = 3; i <= N; i++ )
    {
        for ( int j = 1; j < i-1; j++ )
            M[V[i-1]+V[j]]++;
        
        int K = L - V[i];
        
        for ( int j = i+1; j <= N ; j++ )
        {
            if ( K - V[j] >= 0 ) total += M[K-V[j]]; 
            else break;
        }
    }
    
    printf("%d", total);
}