Pagini recente » Cod sursa (job #1628255) | Cod sursa (job #1719982) | Cod sursa (job #573325) | Cod sursa (job #87049) | Cod sursa (job #1027128)
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
class El{
public:int a,b,c,s;
El(int aa,int bb,int cc):a(aa),b(bb),c(cc),s(aa+bb+cc){};
bool operator<(const El& other)const{return s<other.s;}
bool operator>(const El& other)const{return s>other.s;}
};
int main(){
vector<El> vs;
int x,n,sum;
vector<int> v;
freopen("loto.in","r",stdin);
freopen("loto.out","w",stdout);
cin>>n>>sum;
for(int i=0;i<n;i++){
cin>>x;
v.push_back(x);
for(int j=i;j>=0;j--)
for(int k=j;k>=0;k--){
vs.push_back(El(v[i],v[j],v[k]));
}
}
sort(vs.begin(),vs.end());
bool ok = false;
for(vector<El>::iterator it =vs.begin();it!=vs.end();it++){
vector<El>::iterator it2 = lower_bound(vs.begin(), vs.end(), El(sum-it->s,0,0));
if(it2!=vs.end() && it->s + it2->s==sum) {
ok=true;
cout<<it2->a<<" "<<it2->b<<" "<<it2->c<<" "<<it->a<<" "<<it->b<<" "<<it->c;
break;
}
}
if(!ok) cout<<"-1";
return 0;
}