Pagini recente » Cod sursa (job #1770787) | Cod sursa (job #1915873) | Cod sursa (job #449332) | Cod sursa (job #1202160) | Cod sursa (job #2871209)
#include <fstream>
#include <unordered_map>
using namespace std;
const int Nmax = 105;
int n, a[Nmax], S;
struct Triplet {
int x, y, z;
};
unordered_map<int, Triplet> sume;
int main()
{
ifstream fin("loto.in");
ofstream fout("loto.out");
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<<'\n';
return 0;
}
}
}
}
fout<<"-1\n";
return 0;
}