Pagini recente » Cod sursa (job #785088) | Cod sursa (job #3226535) | Cod sursa (job #3203145) | Cod sursa (job #2263324) | Cod sursa (job #2823695)
#include <bits/stdc++.h>
using namespace std;
const int dim = 105;
int n, a[dim], s;
struct triplet
{
int x;
int y;
int z;
};
unordered_map<int, triplet> sum;
int main()
{
ifstream f("loto.in");
ofstream g("loto.out");
f >> n >> s;
for(int i = 1; i <= n; i++)
f >> a[i];
for(int i = 1; i <= n; i++)
{
for(int j = i; j <= n; j++)
{
for(int k = j; k <= n; k++)
{
sum[a[i] + a[j] + a[k]] = {a[i], a[j], a[k]};
}
}
}
for(int i = 1; i <= n; i++)
{
for(int j = i; j <= n; j++)
{
for(int k = j; k <= n; k++)
{
int c = s - a[i] - a[j] - a[k];
if(sum.count(c))
{
triplet t = sum[c];
g << a[i] << ' ' << a[j] << ' ' << a[k] << ' ' << t.x << ' ' << t.y << ' ' << t.z;
return 0;
}
}
}
}
g << -1;
return 0;
}