-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumOfFourVal.cpp
More file actions
46 lines (46 loc) · 1.37 KB
/
Copy pathSumOfFourVal.cpp
File metadata and controls
46 lines (46 loc) · 1.37 KB
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
#include "bits/stdc++.h"
// #include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,x;
cin>>n>>x;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
vector<vector<int>> ans;
multimap<long long,pair<int,int> > m;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
m.insert(make_pair(arr[i]+arr[j],make_pair(i+1,j+1)));
}
}
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(m.find(x-arr[i]-arr[j])!=m.end()){
auto it=m.find(x-arr[i]-arr[j]);
while(it!=m.end()&&it->first==x-arr[i]-arr[j]){
if(it->second.first!=i+1&&it->second.second!=i+1&&it->second.first!=j+1&&it->second.second!=j+1){
vector<int> v;
v.push_back(arr[i+1]);
v.push_back(arr[j+1]);
v.push_back(arr[it->second.first]);
v.push_back(arr[it->second.second]);
sort(v.begin(),v.end());
ans.push_back(v);
}
it++;
}
}
}
}
for(int i=0;i<ans.size();i++){
for(int j=0;j<ans[i].size();j++){
cout<<ans[i][j]<<" ";
}
cout<<endl;
}
cout<<"IMPOSSIBLE"<<endl;
}