Advertisement
Josif_tepe

Untitled

May 12th, 2024
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 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.     vector<pair<int, int>> v(n);
  8.  
  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.     int L = 0, R = n - 1;
  15.     while(L < R) {
  16.         if(v[L].first + v[R].first == k) {
  17.             cout << v[L].second + 1 << " " << v[R].second + 1 << endl;
  18.             return 0;
  19.         }
  20.         if(v[L].first + v[R].first > k) {
  21.             R--;
  22.         }
  23.         else {
  24.             L++;
  25.         }
  26.  
  27.     }
  28.     cout << "IMPOSSIBLE" << endl;
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement