Pagini recente » Cod sursa (job #909608) | Borderou de evaluare (job #288049) | Cod sursa (job #2090562) | Cod sursa (job #365378) | Cod sursa (job #1042239)
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <stdlib.h>
#include <algorithm>
#define pb push_back
#define nmax 105
#define MOD 666013
#define loc s%MOD
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");
int N;
long S;
vector <long> H[MOD], v;
vector <long>::iterator it, it2;
vector <long> :: iterator find ( long s )
{
for ( it = H[loc].begin(); it != H[loc].end(); it += 4 )
if ( *it == s ) return it;
return H[loc].end();
}
int main()
{
long x, lo=3, hi=0, s;
bool gasit = false;
in >> N >> S;
for ( int i=1; i<=N; ++i )
{
in >> x;
v.push_back(x);
}
for ( unsigned int i=0; i<N; ++i )
for ( unsigned int j=i; j<N; ++j )
for ( unsigned int k=i; k<N; ++k )
{
s = v[i] + v[j] + v[k];
if ( find(s) == H[loc].end() )
{
H[loc].pb(s);
H[loc].pb(v[i]);
H[loc].pb(v[j]);
H[loc].pb(v[k]);
hi = max(hi, s);
}
}
for ( unsigned int i=0; i<=hi%MOD; ++i )
{
for ( it = H[i].begin(); it != H[i].end(); it += 4 )
{
s = S - *it;
for ( it2 = H[loc].begin(); it2 != H[loc].end(); it2 += 4 )
if ( *it2 == s )
{
out << *(it+1) << " " << *(it+2) << " " << *(it+3) << " " << *(it2+1) << " " << *(it2+2) << " " << *(it2+3) << '\n';
gasit = true;
exit(0);
}
}
}
if ( !gasit ) out << -1 << '\n';
return 0;
}