Pagini recente » Cod sursa (job #1662890) | Cod sursa (job #1317130) | Cod sursa (job #533735) | Cod sursa (job #531390) | Cod sursa (job #2285850)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("oite.in");
ofstream fout("oite.out");
#define MAXP 100007
int v[1025], cnt;
vector <int> hashh[100010];
void insertt(int s){
int modulo = s % MAXP;
hashh[modulo].push_back(s);
}
int query(int s){
int modulo = s % MAXP, contor = 0;
for(int i = 0; i < hashh[modulo].size(); ++i){
if(hashh[modulo][i] == s)
contor ++;
}
return contor ;
}
int main()
{
int n, S;
fin >> n >> S;
for(int i = 1; i <= n; ++i)
fin >> v[i];
sort(v + 1, v + n + 1);
for(int i = 1; i < n; i++){
for(int j = i + 1; j <= n; j++){
int suma = v[i] + v[j];
if (suma > S) continue;
cnt += query(S - suma);
}
for(int j = 1; j < i; ++j){
insertt(v[i] + v[j]);
}
}
fout << cnt ;
return 0;
}
//int n, m , matrix [201][201], dp[201][201];