fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool twoSum(vector<int>& a , int target){
  5. unordered_set<int>st;
  6. for(int i=0;i<a.size();i++){
  7. int comp = target-a[i];
  8. if(st.find(comp)!=st.end()){
  9. return true;
  10. }
  11. st.insert(a[i]);
  12. }
  13. return false;
  14. }
  15.  
  16. int main() {
  17. int n;
  18. cin >> n;
  19. vector<int> arr(n);
  20.  
  21. for (int i = 0; i < n; i++) {
  22. cin >> arr[i];
  23. }
  24.  
  25. int target;
  26. cin >> target;
  27.  
  28. cout << (twoSum(arr, target) ? "True" : "False");
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5300KB
stdin
5
1 -2 -1 1 3
-2
stdout
False