Pagini recente » Cod sursa (job #2201280) | Cod sursa (job #302583) | Statistici Anna Perkelo (annamerkeltw) | Cod sursa (job #1568614) | Cod sursa (job #1573344)
#include <fstream>
#include <unordered_map>
using namespace std;
struct triplet
{
int a, b, c;
triplet(int x, int y, int z)
{
a = x;
b = y;
c = z;
}
triplet()
{
a = b = c = 0;
}
};
int main()
{
int N, S, V[102], i, j, k, tmpSum;
unordered_map<int, triplet> m;
ifstream f("loto.in");
f >> N >> S;
for (i = 1; i <= N; i++)
{
f >> V[i];
}
f.close();
for (i = 1; i <= N; i++)
{
for (j = 1; j <= N; j++)
{
for (k = 1; k <= N; k++)
{
tmpSum = V[i] + V[j] + V[k];
//tuple<int, int, int> t(i, j, k);
triplet t(i, j, k);
//m.insert(pair<int, triplet>(tmpSum, t));
m[tmpSum] = t;
}
}
}
ofstream g("loto.out");
for (i = 1; i <= N; i++)
{
for (j = 1; j <= N; j++)
{
for (k = 1; k <= N; k++)
{
tmpSum = S - (V[i] + V[j] + V[k]);
triplet t = m[tmpSum];
if (t.a)
{
g << V[i] << " " << V[j] << " " << V[k] << " " << V[t.a] << " " << V[t.b] << " " << V[t.c] << flush;
return 0;
}
}
}
}
g << -1;
g.close();
return 0;
}