Pagini recente » Cod sursa (job #1989263) | Cod sursa (job #2746357) | Cod sursa (job #2151303) | Cod sursa (job #1568988) | Cod sursa (job #2437258)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
const int nmax = 101;
const int p = 370003;
int n, s, v[nmax], index[10];
struct punct
{
int i1, i2, i3;
};
punct pct;
bool ok = false;
vector < int > h[p + 2];
int SearchSum(int sum)
{
for(int i = 1; i <= n; ++i)
for(int j = i; j <= n; ++j)
for(int k = j; k <= n; ++k)
if(v[i] + v[j] + v[k] == sum)
{
pct.i1 = i;
pct.i2 = j;
pct.i3 = k;
return 1;
}
return 0;
}
void Solve()
{
int S = 0, complement;
for(int i = 1; i <= n; ++i)
for(int j = i; j <= n; ++j)
for(int k = j; k <= n; ++k)
{
S = v[i] + v[j] + v[k];
int r = S % p;
if(h[r].size() == 0 || h[r][0] != S)
{
h[r].push_back(S);
}
}
for(int i = 1; i <= n && !ok; ++i)
for(int j = i; j <= n && !ok; ++j)
for(int k = j; k <= n && !ok; ++k)
{
S = v[i] + v[j] + v[k];
complement = s - S;
if(complement > 0)
{
int r = complement % p;
for(int t = 0; t < h[r].size(); t++)
{
if(h[r][t] == complement)
{
index[1] = i;
index[2] = j;
index[3] = k;
t = SearchSum(complement);
index[4] = pct.i1;
index[5] = pct.i2;
index[6] = pct.i3;
ok = true;
}
}
}
}
}
int main()
{
fin >> n >> s;
for(int i = 1; i <= n; ++i)
fin >> v[i];
Solve();
if(ok)
{
sort(index + 1, index + 7);
for(int i = 1; i <= 6; ++i)
fout << v[index[i]] << " ";
}
else
fout << "-1\n";
return 0;
}