forked from rathoresrikant/competitive-programming-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAggresiveCows.cpp
More file actions
51 lines (51 loc) · 944 Bytes
/
AggresiveCows.cpp
File metadata and controls
51 lines (51 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int hash[100000];
int hash1[100000];
int main() {
int t;
cin>>t;
while(t--)
{int n,m;
cin>>n>>m;
int a[n],i;
for(i=0;i<n;i++)
{cin>>a[i];
if(a[i]<0)
hash1[-1*a[i]]++;
else
hash[a[i]]++;
}
int ans=0;
for(i=-100000;i<100000;i++)
{if(i<0&&m-i<0)
{if(i==m-i)
ans+=hash1[-1*i]*(hash1[-1*(m-i)]-1);
else
ans+=hash1[-1*i]*hash1[-1*(m-i)];
}
else if(i<0&&m-i>=0)
{if(i==m-i)
ans+=hash1[-1*i]*(hash[m-i]-1);
else
ans+=hash1[-1*i]*hash[m-i];
}
else if(i>=0&&m-i<0)
{if(i==m-i)
ans+=hash[i]*(hash1[-1*(m-i)]-1);
else
ans+=hash[i]*hash1[-1*(m-i)];
}
else if(i>=0&&m-i>=0)
{if(i==m-i)
ans+=hash[i]*(hash[m-i]-1);
else
ans+=hash[i]*hash[m-i];
}
}
ans/=2;
cout<<ans<<"\n";
}
return 0;
}