I'm getting stuck in a weird infinite loop while using map in c++. The first code works good and outputs numbers.
The test cases are:
5 2
1 2 3 4 5
long long N, K, count = 0;
cin>>N>>K;
long long l;
map<long long, long long> mp;
for(int i = 0; i<N; i++){
cin>>l;
++mp[l];
}
for(auto a:mp){
cout<<a.first + K<<" "<<a.first - K;
}
For the next code I'm getting stuck into an infinite loop, for the same test case, don't know why?
long long N, K, count = 0;
cin>>N>>K;
long long l;
map<long long, long long> mp;
for(int i = 0; i<N; i++){
cin>>l;
++mp[l];
}
for(auto a:mp){
cout<<mp[a.first + K]<<" "<<mp[a.first - K];
}
The last code keeps on printing 0 till an infinite loop. Any idea why?