Pagini recente » Cod sursa (job #522306) | Cod sursa (job #2554077) | Cod sursa (job #631508) | Cod sursa (job #65755) | Cod sursa (job #1238274)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
int a[100], x, n;
int main()
{
f >> x >> n;
for (int i = 1; i <= x; i++)
{
f >> a[i];
}
for (int i = 1; i <= x; i++)
for (int j = 1; j <= x; j++)
if (a[i] < a[j])
{
int temp = a[j];
a[j] = a[i];
a[i] = temp;
}
int S = 0;
int l = 0;
while (S < n)
{
if (x <= 0) break;
int t = S + a[x];
if (t > n) x = x - 1;
else
{
l = 1;
g << a[x] << " ";
S = t;
}
cout << S << endl;
}
if (l == 0) g << "-1";
}