Pagini recente » Cod sursa (job #2110260) | Cod sursa (job #790116) | Cod sursa (job #2474353) | Cod sursa (job #838622) | Cod sursa (job #1743759)
#include <fstream>
#include <iostream>
#include <set>
struct h{
int a,b;
};
using namespace std;
h comb[100000000];
long v[100],n,s,cnt;
set<long>a;
set<long>::iterator it1,it2;
ifstream f("loto.in");
ofstream g("loto.out");
void citire(){
f>>n>>s;
for(int i=0;i<n;i++)
{
f>>v[i];
}
f.close();
}
bool ok;
void make_set(){
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
a.insert(v[i]+v[j]);
comb[cnt].a=v[i];
comb[cnt++].b=v[j];
}
}
}
void afisare(){
long a=*it1,b=*it2,c=s-*it1-*it2;
for(int i=0;i<cnt;i++){
if(comb[i].a+comb[i].b==a){a=-1;g<<comb[i].a<<" "<<comb[i].b<<" ";}
if(comb[i].a+comb[i].b==b){b=-1;g<<comb[i].a<<" "<<comb[i].b<<" ";}
if(comb[i].a+comb[i].b==c){c=-1;g<<comb[i].a<<" "<<comb[i].b<<" ";}
}
ok=true;
}
void fun(){
for(it1=a.begin();it1!=a.end();it1++){
for(it2=it1;it2!=a.end();it2++){
if(a.find(s-*it1-*it2)!=a.end()++){
afisare();
return;
}
}
}
}
int main(){
citire();
make_set();
int nr=*a.end();
if(3*n>=s)fun();
if(!ok)g<<-1;
}