-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcses_1642.cpp
More file actions
39 lines (36 loc) · 954 Bytes
/
cses_1642.cpp
File metadata and controls
39 lines (36 loc) · 954 Bytes
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
#include <bits/extc++.h>
using namespace std;
int64_t n, x;
vector<pair<int64_t, int64_t>> a;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> x;
a.resize(n);
for (int i = 0; i < n; i++)
{
cin >> a[i].first;
a[i].second = i + 1;
}
sort(a.begin(), a.end());
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
{
int64_t tar = x - a[i].first - a[j].first;
for (int l = j + 1, r = n - 1; l < r;)
{
if (a[l].first + a[r].first > tar)
r--;
else if (a[l].first + a[r].first < tar)
l++;
else
{
cout << a[i].second << " " << a[j].second << " " << a[l].second << " " << a[r].second << '\n';
return 0;
}
}
}
cout << "IMPOSSIBLE\n";
return 0;
}