Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- int n, x;
- cin >> n >> x;
- int niza[n], orginalna[n];
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- orginalna[i] = niza[i];
- }
- sort(niza, niza + n);
- int i = 0, j = n - 1;
- while(i < j) {
- if(niza[i] + niza[j] == x) {
- for(int k = 0; k < n; k++) {
- if(niza[i] == orginalna[k]) {
- cout << k + 1 << endl;
- orginalna[k] = -1;
- break;
- }
- }
- for(int k = 0; k < n; k++) {
- if(niza[j] == orginalna[k]) {
- cout << k + 1 << endl;
- orginalna[k] = -1;
- break;
- }
- }
- return 0;
- }
- if(niza[i] + niza[j] < x) {
- i++;
- }
- else {
- j--;
- }
- }
- cout << "IMPOSSIBLE" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement