Advertisement
tepyotin2

Sum Of Two Values

May 1st, 2025
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_map>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     long long x;
  8.     cin >> n >> x;
  9.  
  10.     unordered_map<long long, int> seen;
  11.     for (int i = 1; i <= n; ++i) {
  12.         long long num;
  13.         cin >> num;
  14.         long long complement = x - num;
  15.  
  16.         if (seen.count(complement)) {
  17.             // Found the pair
  18.             cout << seen[complement] << " " << i << endl;
  19.             return 0;
  20.         }
  21.  
  22.         seen[num] = i;
  23.     }
  24.  
  25.     cout << "IMPOSSIBLE" << endl;
  26.     return 0;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement