-
Notifications
You must be signed in to change notification settings - Fork 0
/
1641.cpp
55 lines (45 loc) · 946 Bytes
/
1641.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n, x;
cin >> n >> x;
vector<pair<ll, ll>> arr;
int m = 0;
for(ll i = 1; i <= n; i++)
{
ll a;
cin >> a;
pair<ll, ll> p;
p.first = a;
p.second = i;
arr.push_back(p);
}
sort(begin(arr), end(arr));
for(ll i = 0; i < n; i++)
{
ll l = 0, r = n - 1;
ll target = x - arr.at(i).first;
while(l != r)
{
if(l != i && r != i && arr.at(l).first + arr.at(r).first == target)
{
m = 1;
cout << arr.at(i).second << " " << arr.at(l).second << " " << arr.at(r).second << "\n";
break;
}
if(arr.at(l).first + arr.at(r).first < target)
l++;
else
r--;
}
if(m == 1)
break;
}
if(m == 0)
{
cout << "IMPOSSIBLE" << "\n";
}
return 0;
}