Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- typedef long long ll;
- using namespace std;
- struct Elem {
- ll val;
- ll pos;
- };
- bool operator<(const Elem& lhs, const Elem& rhs) {
- return lhs.val < rhs.val;
- }
- int main() {
- ll n, x;
- cin >> n >> x;
- vector<Elem> a(n);
- for (ll i = 0; i < n; ++i) {
- ll value;
- cin >> value;
- a[i] = {value, i};
- }
- sort(a.begin(), a.end());
- for (ll i1 = 0; i1 < n; ++i1) {
- for (ll i2 = i1 + 3; i2 < n; ++i2) {
- ll part = a[i1].val + a[i2].val;
- ll left = i1 + 1;
- ll right = i2 - 1;
- while (left < right) {
- ll tmp_sum = (a[left].val + a[right].val + part);
- if (tmp_sum == x) {
- vector<ll> indices = {
- a[left].pos,
- a[right].pos,
- a[i1].pos,
- a[i2].pos
- };
- sort(indices.begin(), indices.end());
- for (auto index : indices) {
- cout << index + 1 << " ";
- }
- return 0;
- } else if (tmp_sum < x) {
- ++left;
- } else {
- --right;
- }
- }
- }
- }
- cout << "IMPOSSIBLE" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement