Pagini recente » Cod sursa (job #398177) | Cod sursa (job #1095220) | Cod sursa (job #265271) | Cod sursa (job #1975982) | Cod sursa (job #2919211)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin ("loto.in");
ofstream fout("loto.out");
const int DIM = 101;
const int TOKEN_DIM = 7;
int n, s, cnt = 0;
int v[DIM], sol[TOKEN_DIM];
int main() {
fin >> n >> s;
for (int i = 1; i <= n; i++)
fin >> v[i];
sort(v + 1, v + n + 1);
int index = n, steps = 1;
while (s > 0 && index > 0 && steps <= 6) {
if (s >= v[index]) {
s -= v[index];
sol[++cnt] = v[index];
steps++;
}
else
index--;
}
if (s > 0)
fout << -1;
else {
for (int i = cnt; i >= 1; i--)
fout << sol[i] << ' ';
}
return 0;
}