Advertisement
Josif_tepe

Untitled

Jul 13th, 2024
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 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 i = 0; i < n; i++) {
  18.     for(int j = i + 1; j < n; j++) {
  19.       int L = j + 1, R = n - 1;
  20.       while(L < R) {
  21.         ll sum = niza[i].first + niza[j].first + niza[L].first + niza[R].first;
  22.         if(sum == x) {
  23.           cout << niza[i].second + 1 << " " << niza[j].second  +1 << " " << niza[L].second + 1 << " " << niza[R].second + 1 << endl;
  24.           return 0;
  25.         }
  26.         if(sum < x) {
  27.           L++;
  28.         }
  29.         else {
  30.           R--;
  31.         }
  32.       }
  33.     }
  34.   }
  35.   cout << "IMPOSSIBLE" << endl;
  36.  
  37.   return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement