Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- #include<iomanip>
- #include<algorithm>
- #include<cstdlib>
- #include<cstring>
- #include<vector>
- #include<utility>
- #define ll long long
- #define sz(x) int(x.size())
- #define all(x) x.begin(),x.end()
- #define rall(s) s.rbegin(), s.rend()
- #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
- using namespace std;
- void Fast_IO(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- void solve(){
- ll n,k; cin>>n>>k;
- vector<ll>v;
- vector<ll>negative(10000005);
- vector<ll>positive(10000005);
- while(n--){
- ll x; cin>>x;
- if(x<0){
- if(negative[abs(x)]==0){
- v.push_back(x);
- }
- negative[abs(x)]++;
- }else{
- if(positive[x]==0){
- v.push_back(x);
- }
- positive[x]++;
- }
- }
- ll counter=0;
- if(k==0){
- for(int i=0;i<sz(v);i++){
- if(v[i]<0){
- if(negative[abs(v[i])]>1) counter++;
- }else{
- if(positive[v[i]]>1) counter++;
- }
- }
- }else{
- for(int i=0;i<sz(v);i++){
- if(v[i]<0){
- if(negative[abs(k-v[i])] and abs(k-v[i]) != abs(v[i])) counter++;
- }else{
- if(positive[abs(k-v[i])] && abs(k-v[i]) != abs(v[i])) counter++;
- }
- }
- }
- cout<<counter;
- }
- int main(){
- Fast_IO();
- int t =1;
- //cin>>t;
- while(t--){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement