Pagini recente » Cod sursa (job #513218) | Cod sursa (job #3280049) | Cod sursa (job #1340836) | Cod sursa (job #48352) | Cod sursa (job #3128295)
#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 = i; j < n; j++)
for(int k = j; k < n; k++)
if(sol[index] == nr[i] + nr[j] + nr[k]){
fout << nr[i] << " " << nr[j] << " " << nr[k] << " ";
return;
}
}
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 = i; j < n; j++)
for(int k = j; 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";
}