Pagini recente » Cod sursa (job #778259) | Cod sursa (job #427586) | Cod sursa (job #2280601) | Cod sursa (job #997302) | Cod sursa (job #3155754)
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
struct triplet
{
int x, y, z;
};
int n, a[101], s;
unordered_map<int, triplet> sume;
int main()
{
fin >> n >> s;
for(int i = 1; i <= n; i ++){
fin >> a[i];
}
for(int i = 1; i <= n; i ++){
for(int j = i; j <= n; j ++){
for(int k = j; k <= n; k ++){
sume[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 complement = s - a[i] - a[j] - a[k];
if(sume.count(complement) > 0) {
triplet t = sume[complement];
fout << a[i] << " " << a[j] << " " << a[k] << " " << t.x << " " << t.y << " " << t.z;
return 0;
}
}
}
}
fout << -1;
return 0;
}