Advertisement
Josif_tepe

Untitled

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