Advertisement
Josif_tepe

Untitled

Jul 13th, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.   int n, x;
  7.   cin >> n >> x;
  8.  
  9.   pair<int, int> niza[n];
  10.   for(int i = 0; i < n; i++) {
  11.       cin >> niza[i].first;
  12.       niza[i].second = i;
  13.   }
  14.  
  15.   sort(niza, niza + n);
  16.   int i = 0, j = n - 1;
  17.  
  18.   while(i < j) {
  19.     if(niza[i].first + niza[j].first == x) {
  20.       cout << niza[i].second + 1 << " " << niza[j].second + 1 << endl;
  21.       return 0;
  22.     }
  23.     if(niza[i].first + niza[j].first < x) {
  24.       i++;
  25.     }
  26.     else {
  27.       j--;
  28.     }
  29.   }
  30.  
  31.  
  32.   cout << "IMPOSSIBLE" << endl;
  33.   return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement