Pagini recente » Cod sursa (job #2028033) | Cod sursa (job #2091331) | Cod sursa (job #1874114) | Cod sursa (job #1003480) | Cod sursa (job #2947853)
#include <fstream>
#include <list>
#include <vector>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
struct sumstorage
{
int sum, a, b, c;
};
vector <sumstorage> v;
const int mod = 24499;
list <sumstorage> h[mod];
bool eql (sumstorage x, sumstorage y)
{
if (x.sum != y.sum)
return 0;
if (x.a != y.a)
return 0;
if (x.b != y.b)
return 0;
if (x.c != y.c)
return 0;
return 1;
}
bool check(sumstorage x)
{
list <sumstorage> :: iterator it;
for (it = h[x.sum%mod].begin(); it != h[x.sum%mod].end(); it++)
{
if (eql(*it, x))
return 0;
}
return 1;
}
void ins (sumstorage x)
{
if (check(x))
h[x.sum%mod].push_back(x);
}
bool isThere (sumstorage &out, int x)
{
list <sumstorage> :: iterator it;
if (x < 0) return 0;
for (it = h[x%mod].begin(); it != h[x%mod].end(); it++)
{
if ((*it).sum == x)
{
out = *it;
return 1;
}
}
return 0;
}
int n, s, i, j, k, x, a[101];
sumstorage t;
int main()
{
fin >> n >> s;
for (i = 1; i <= n; i++)
fin >> a[i];
for (i = 1; i <= n; i++)
for (j = i; j <= n; j++)
for (k = j; k <= n; k++)
{
t.sum = a[i]+a[j]+a[k];
t.a = i; t.b = j; t.c = k;
v.push_back(t);
ins(t);
}
for (i = 0; i < v.size(); i++)
{
t.sum = -1;
isThere(t, s-v[i].sum);
if (t.sum != -1)
break;
}
if (t.sum == -1)
fout << "-1\n";
else
fout << v[i].a << ' ' << v[i].b << ' ' << v[i].c << ' ' << t.a << ' ' << t.b << ' ' << t.c << '\n';
return 0;
}