Pagini recente » Cod sursa (job #465734) | Cod sursa (job #2235228) | Cod sursa (job #2600735) | Cod sursa (job #563684) | Cod sursa (job #3154229)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin ("loto.in");
ofstream cout ("loto.out");
pair < pair <int , int> , pair <int , int> > optiuni[1000001];
int main ()
{
int lungime , suma;
cin >> lungime >> suma;
int sir[101] , total = 0;
for (int indice_1 = 1 ; indice_1 <= lungime ; indice_1++)
{
cin >> sir[indice_1];
for (int indice_2 = 1 ; indice_2 <= indice_1 ; indice_2++)
for (int indice_3 = 1 ; indice_3 <= indice_2 ; indice_3++)
optiuni[++total] = make_pair(make_pair(sir[indice_1] + sir[indice_2] + sir[indice_3] , sir[indice_1]) , make_pair(sir[indice_2] , sir[indice_3]));
}
sort(optiuni + 1 , optiuni + total + 1);
for (int stanga = 1 , dreapta = total ; stanga <= dreapta ; dreapta--)
{
while (stanga < dreapta && optiuni[stanga].first.first < suma - optiuni[dreapta].first.first)
stanga++;
if (optiuni[stanga].first.first + optiuni[dreapta].first.first == suma)
{
int termeni[7] = {0};
for (int repetitie = 1 , indice = stanga ; repetitie <= 2 ; repetitie++ , indice = dreapta)
{
termeni[++termeni[0]] = optiuni[indice].first.second;
termeni[++termeni[0]] = optiuni[indice].second.first;
termeni[++termeni[0]] = optiuni[indice].second.second;
}
sort(termeni + 1 , termeni + 7);
for (int indice = 1 ; indice <= 6 ; indice++)
cout << termeni[indice] << ' ';
cout.close(); cin.close();
return 0;
}
}
cout << "-1";
cout.close(); cin.close();
return 0;
}