Advertisement
Josif_tepe

Untitled

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