File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
CSES/Sorting_and_Searching Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ written by Pankaj Kumar.
3+ country:-INDIA
4+ */
5+ #include < bits/stdc++.h>
6+ using namespace std ;
7+ typedef long long ll;
8+
9+ int solve ()
10+ {
11+ int n, x;
12+ cin >> n >> x;
13+ unordered_map<int , pair<int , int >> mp;
14+ vector<int > v (n);
15+ for (auto &x : v)
16+ {
17+ cin >> x;
18+ }
19+ for (int i = 0 ; i < n; i++)
20+ {
21+ for (int j = 0 ; j < i; j++)
22+ {
23+ int temp_sum = v[i] + v[j];
24+ int req_sum = x - temp_sum;
25+ if (req_sum <= 0 )
26+ {
27+ continue ;
28+ }
29+ if (mp.find (req_sum) != mp.end ())
30+ {
31+ pair<int , int > t = mp[req_sum];
32+ if (t.first != i && t.first != j && t.second != i && t.second != j)
33+ {
34+ cout << t.first + 1 << " " << t.second + 1 << " " << i + 1 << " " << j + 1 << endl;
35+ return 0 ;
36+ }
37+ }
38+ mp[temp_sum] = {i, j};
39+ }
40+ }
41+ cout << " IMPOSSIBLE" << endl;
42+ return 0 ;
43+ }
44+ int main ()
45+ {
46+ int testCase = 1 ;
47+ // cin>>testCase;
48+ while (testCase--)
49+ {
50+ solve ();
51+ }
52+ return 0 ;
53+ }
You can’t perform that action at this time.
0 commit comments