Pagini recente » Cod sursa (job #583535) | Cod sursa (job #1038649) | Cod sursa (job #1103771) | Cod sursa (job #1068993) | Cod sursa (job #2839398)
#include <fstream>
using namespace std;
ifstream cin("loto.in");
ofstream cout("loto.out");
struct sol
{
int x, y, z;
};
const int NMAX = 103, MOD = 666013, REAL = 1092727;
int v[NMAX], urm[REAL], r[MOD];
pair <int, sol> a[REAL];
int check(int x)
{
int rest = x % MOD, last = 0;
for (int i = r[rest]; i != 0; last = i, i = urm[i])
if (a[i].first == x)
return (-1) * i;
return last;
}
int main()
{
int n, s, i, j, k, dim = 0;
cin >> n >> s;
for (i = 1; i <= n; i++)
cin >> v[i];
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
for (k = 1; k <= n; k++)
{
sol aux;
aux.x = v[i];
aux.y = v[j];
aux.z = v[k];
int sum = v[i] + v[j] + v[k], last, la = sum % MOD;
last = check(sum);
a[++dim] = {sum, aux};
if (last >= 0)
{
if (!r[la])
r[la] = dim;
else
urm[last] = dim;
}
}
return 0;
for (i = 0; i < MOD; i++)
for (j = r[i]; j != 0; j = urm[j])
{
int aux = check(s - a[j].first);
if (aux < 0)
{
aux *= -1;
cout << a[j].second.x << " " << a[j].second.y <<
" " << a[j].second.z << " " << a[aux].second.x <<
" " << a[aux].second.y << " " << a[aux].second.z;
return 0;
}
}
cout << -1;
}