-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSES1642.cpp
56 lines (45 loc) · 1.07 KB
/
CSES1642.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
56
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define pb push_back
const ll MOD = 1e9 + 7;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, x;
cin >> n >> x;
vector<pair<ll, int> > v(n);
for(int i = 0; i < n; i++) {
cin >> v[i].F;
v[i].S = i + 1;
}
sort(v.begin(), v.end());
for(int i = 0; i < n - 1; i++) {
for(int j = i + 1; j < n; j++) {
ll target = v[i].F + v[j].F;
int left = j + 1, right = n - 1;
while(left < right) {
ll sum = target + v[left].F + v[right].F;
if(sum == x) {
cout << v[i].S << ' ' << v[j].S << ' ' << v[left].S << ' ' << v[right].S;
return 0;
}
else if(sum > x) right--;
else left++;
}
}
}
cout << "IMPOSSIBLE";
}
/*
RILY <3
NEVER GIVE UP!!!
*/