Pls tell me all the information about this mp.find(x)!=mp.end()

this is the question
answer
#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main()

{

ios_base::sync_with_stdio(false);

cin.tie(NULL);

int n, s, ans=0;

cin>>n;

unordered_map<int, int> mp;

for(int i=0; i<n; ++i)

{

int x, y;

cin>>x>>y;

mp[x+y]++;

}

cin>>s;

for(auto i:mp)

{

int z = i.first-s;

if(mp.find(z)!=mp.end())

    ans+= (i.second * mp[z]);

}

cout<<ans<<endl;

}
explain me i am a beginner
map has stored all the x+y values but it has not stored the x+y-s then how can we find x+y-s
in map, if it is happening pls explaing about how can we use this if(mp.find(z)!=mp.end()) and it is giving the count;

Through this if condition, you are finding out the presence of key ‘k’ in the map, if that key is not present, it returns an iterator pointing past the last element of the map (which is mp.end() ) . As long as find does not return mp.end(), we know that the key is present in the map.

2 Likes