Pagini recente » Cod sursa (job #13759) | Cod sursa (job #1722663) | Cod sursa (job #3251218) | Cod sursa (job #841982) | Cod sursa (job #3128144)
#include <bits/stdc++.h>
#define maxn 105
int sol[maxn * maxn * maxn];
int nr[maxn];
int n;
std::ifstream fin("loto.in");
std::ofstream fout("loto.out");
void afis(int index)
{
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
for(int k = 0; k < n; k++)
if(sol[index] == nr[i] + nr[j] + nr[k])
fout << nr[i] << " " << nr[j] << " " << nr[k] << " ";
}
int main()
{
int S;
fin >> n >> S;
long long int cnt = 0;
for (int i = 0; i < n; i++)
fin >> nr[i];
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
for(int k = 0; k < n; k++)
sol[cnt++] = nr[i] + nr[j] + nr[k];
std::sort(sol, sol+cnt);
int i = 0, j = cnt - 1;
bool ok = false;
while(i <= j){
if(sol[i] + sol[j] == S)
{
afis(i);
afis(j);
ok = true;
break;
}
while(sol[i] + sol[j] > S)
{
j--;
}
while(sol[i] + sol[j] < S){
i++;
}
}
if(ok == false)
fout << "-1";
}