Pagini recente » Cod sursa (job #1400440) | Cod sursa (job #2400064) | Cod sursa (job #133622) | Cod sursa (job #582674) | Cod sursa (job #1040879)
#include<fstream>
#include<vector>
#define numaru 666019
using namespace std;
vector <long long> v[numaru];
long long w[100];
ifstream f("loto.in");
ofstream g("loto.out");
bool cauta(long long x)
{
long long unde=x%numaru;
vector <long long> :: iterator i;
for(i=v[unde].begin(); i!=v[unde].end(); ++i)
if(*i==x) return true;
return false;
}
void adauga(long long x)
{
long long unde=x%numaru;
if(cauta(x)==false) v[unde].push_back(x);
}
int main()
{
int n,k,q,p;
long long x,a[2],s[6],y;
f>>n>>x;
a[0]=x/2;
a[1]=x/2+x%2;
y=x;
for(k=0;k<n;++k)
{
f>>x;
w[k]=x;
adauga(x);
}
for(k=0;k<2;++k)
{
s[0+3*k]=-1;
for(p=0;p<n;++p)
for(q=0;q<n;++q)
if( a[k] >= w[p] + w[q] && cauta( a[k] - w[p] - w[q] ) )
{
s[0+3*k]=w[p];
s[1+3*k]=w[q];
s[2+3*k]=a[k] - w[p] - w[q];
q=p=n;
}
}
if(s[0]!=-1 && s[3]!=-1)
{
for(k=0;k<6;++k) {g<<s[k]<<" ";y-=s[k];}
if(y!=0)for(;;);
g<<"\n";
}
else g<<"-1\n";
f.close();
g.close();
return 0;
}