Pagini recente » Cod sursa (job #1560921) | Monitorul de evaluare | Istoria paginii runda/monday | Cod sursa (job #1561694) | Cod sursa (job #1741824)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream is("loto.in");
ofstream os("loto.out");
int n, S, s, a[101], x[7];
bool gasit = false;
void Comb(int k);
void Write();
int main()
{
is >> n >> S;
for ( int i = 1; i <= n; ++i )
is >> a[i];
sort(a+1, a+n+1);
x[0] = 1;
Comb(1);
if ( !gasit )
os << -1;
is.close();
os.close();
return 0;
}
void Comb(int k)
{
if ( s > S )
return;
if ( k > 6 )
{
if ( s == S )
Write();
return;
}
for ( int i = x[k-1]; i <= n; ++i )
{
x[k] = i;
s += a[i];
Comb(k+1);
if ( gasit )
return;
s -= a[i];
}
}
void Write()
{
gasit = true;
for ( int i = 1; i <= 6; ++i )
os << a[x[i]] << ' ';
}