Advertisement
Josif_tepe

Untitled

Nov 4th, 2022
1,008
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 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.     int niza[n];
  11.     for(int i = 0; i < n; i++)
  12.     {
  13.         cin niza[i];
  14.     }
  15.     sort(niza, niza + n);
  16.     int s = 0, e = n - 1;
  17.     while(s < e)
  18.     {
  19.         if(niza[s] + niza[e] == x)
  20.         {
  21.             cout << niza[s] << niza[e] << endl;
  22.         }
  23.         else if(niza[s] + niza[e] < x)
  24.         {
  25.             s++;
  26.         }
  27.         else{e--;}
  28.     }
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement