Josif_tepe

Untitled

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