Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int n, k;
- cin >> n >> k;
- vector<pair<int, int>> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i].first;
- v[i].second = i;
- }
- sort(v.begin(), v.end());
- for(int i = 0; i < n; i++) {
- int L = i + 1, R = n - 1;
- while(L < R) {
- if(v[L].first + v[R].first + v[i].first == k) {
- cout << v[i].second + 1 << " " << v[L].second + 1 << " " << v[R].second + 1 << endl;
- return 0;
- }
- if(v[L].first + v[R].first + v[i].first > k) {
- R--;
- }
- else {
- L++;
- }
- }
- }
- cout << "IMPOSSIBLE" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement