Advertisement
Josif_tepe

Untitled

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