Mai intai trebuie sa te autentifici.
Cod sursa(job #59886)
Utilizator | Data | 10 mai 2007 23:10:38 | |
---|---|---|---|
Problema | Oite | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <stdio.h>
#include <ext/hash_map>
#include <algorithm>
using namespace std;
using namespace __gnu_cxx;
int n, sol;
unsigned s, a[1200];
hash_map <unsigned, unsigned> nr(253237);
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++)
if (nr.find(s-a[k]-a[i])!=nr.end()) sol+=nr[s-a[k]-a[i]];
}
printf("%d\n", sol);
return 0;
}