Pagini recente » Cod sursa (job #2221975) | Cod sursa (job #42819) | Cod sursa (job #2342895) | Cod sursa (job #3190873) | Cod sursa (job #670297)
Cod sursa(job #670297)
#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> ma1, 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=1;i<=poz-2;i++)
ma1[v[i]+v[poz-1]]=0;//ma[v[i]+v[poz-1].erase();
for (i=1;i<=poz-1;i++)
ma1[v[i]+v[poz]]++;
for (i=poz+1;i<=n;i++)
ma2[v[i]+v[poz]]--;//.erase();
for (it=ma1.begin();it!=ma1.end();it++)
{
a=(*it).first; b=s-a;
rez+=(*it).second * ma2[b];
}
}
printf("%ld",rez);
}
int main()
{
freopen("oite.in","r",stdin);
freopen("oite.out","w",stdout);
citire();
rezolvare();
return 0;
}