fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n,x ; cin>>n>>x;
  7. vector<int>arr(n);
  8. for(int i = 0 ; i<n;i++){
  9. cin>>arr[i];
  10. }
  11. unordered_map<int,int>hash;
  12. for(int i =0;i<n;i++){
  13. if(hash.find(x-arr[i])!=hash.end()){
  14. cout<<"pair found "<<arr[i]<<" "<<x-arr[i]<<"\n";
  15. }
  16. hash[arr[i]]=i; }
  17. // your code goes here
  18. return 0;
  19. }
Success #stdin #stdout 0s 5324KB
stdin
5 4 
1 2 3 4 2 
stdout
pair found 3 1
pair found 2 2