Pagini recente » Cod sursa (job #861262) | Monitorul de evaluare | Cod sursa (job #2197662) | Cod sursa (job #1083347) | Cod sursa (job #2746418)
#include <iostream>
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
struct suma_trei
{
int a;
int b;
int c;
};
unordered_map<int, suma_trei> mp;
int main()
{
vector<int> v;
int n, s;
fin>>n>>s;
for(int i=0;i<n;i++)
{
int x;
fin>>x;
v.push_back(x);
}
//memoram toate sumele posibile cu 3 elemente
for(int i=0;i<v.size();i++)
for(int j=0;j<v.size();j++)
for(int k=0;k<v.size();k++)
{
int suma_curenta;
suma_trei t;
suma_curenta = v[i] + v[j] + v[k];
t.a = v[i];
t.b = v[j];
t.c = v[k];
if(mp.find(suma_curenta) == mp.end())
mp[suma_curenta] = t;
else
continue;
}
int ok = 0;
for(auto z: mp)
{
if(mp.find(s - z.first) != mp.end())
{
unordered_map<int,suma_trei>::iterator it;
it = mp.find(s - z.first);
fout<<it->second.a<<" "<<it->second.b<<" "<<it->second.c<<" "<<z.second.a<<" "<<z.second.b<<" "<<z.second.c<<" ";
ok = 1;
break;
}
}
if(ok == 0)
fout<<-1;
return 0;
}