Pagini recente » Cod sursa (job #1754234) | Cod sursa (job #1146547) | Cod sursa (job #1764285) | Cod sursa (job #2341240) | Cod sursa (job #670318)
Cod sursa(job #670318)
#include <stdio.h>
#include <map>
using namespace std;
#define nmax 1030
long n, s, i, v[nmax], j, rez, poz, a, b;
map <int, int> ma2;
map <int, int> :: iterator it;
void citire()
{
scanf("%ld %ld",&n,&s);
for (i=1;i<=n;i++)
scanf("%ld",&v[i]);
}
void rezolvare()
{
for (i=2;i<=n;i++)
for (j=i+1;j<=n;j++)
ma2[v[i]+v[j]]++;
for (poz=2;poz<=n-2;poz++)
{
for (i=poz+1;i<=n;i++)
{
ma2[v[i]+v[poz]]--;
if (ma2[v[i]+v[poz]]==0)
ma2.erase(v[i]+v[poz]);
}
for (i=1;i<=poz-1;i++)
rez+=ma2[s-v[i]-v[poz]];
}
printf("%ld",rez);
}
int main()
{
freopen("oite.in","r",stdin);
freopen("oite.out","w",stdout);
citire();
rezolvare();
return 0;
}