CSES - Shared codeLink to this code:
https://cses.fi/paste/0776e7119f65f2007a8ea2/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <vector>
using namespace std;
using namespace __gnu_pbds;
#ifndef LOCAL
#endif
#define all(x) (x).begin(), (x).end()
typedef long long ll;
template <typename Key, typename Cmp = less<Key>>
using ordered_set =
tree<Key, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>;
template <typename Key, typename Value, typename Cmp = less<Key>>
using ordered_map =
tree<Key, Value, Cmp, rb_tree_tag, tree_order_statistics_node_update>;
template <typename Key>
using min_heap = priority_queue<Key, vector<Key>, greater<Key>>;
template <typename Tp> class vect1 : public vector<Tp> {
public:
using vector<Tp>::vector;
Tp &operator[](size_t idx) { return this->at(idx - 1); }
};
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
struct chash { /// use most bits rather than just the lowest ones
const uint64_t C = ll(2e18 * acos((long double)-1)) + 71; // large odd number
const int RANDOM = (int)rng();
ll operator()(
ll x) const { /// https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
return __builtin_bswap64((x ^ RANDOM) * C);
}
};
template <class K, class V> using ht = gp_hash_table<K, V, chash>;
#define int long long
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, x;
cin >> n >> x;
vect1<int> a(n);
for (auto &y : a)
cin >> y;
ht<int, int> ump;
for (int i = 1; i <= n; i++)
ump[a[i]] = i;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
int val = x - (a[i] + a[j]);
if (ump.find(val) != ump.end()) {
if (ump[val] != i && ump[val] != j) {
cout << i << ' ' << j << ' ' << ump[val];
exit(0);
}
}
}
}
cout << "IMPOSSIBLE";
}