Pagini recente » Cod sursa (job #613784) | Cod sursa (job #2981873) | Cod sursa (job #71072) | Cod sursa (job #2232664) | Cod sursa (job #2670164)
#include <iostream>
#include <vector>
#include <fstream>
#include <unordered_map>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#define ll long long
#define N 101
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
int n, S, nrSecv, el, gasit, a, b, c;
unordered_map<int, priority_queue<int> > m;
vector < vector < pair <int, int> > > liste(7, vector<pair<int, int>>());
int main() {
fin >> n >> S;
for (int i = 1; i <= n; ++i) {
fin >> el;
m[nrSecv].push(el);///la nrSecv se gaseste secventa ...
liste[1].push_back({ el, nrSecv++ });
}
el = 2;
while (el <= 6 && !gasit) {
for (int i = 0; i < liste[el - 1].size(); ++i) {
for (int j = 0; j < liste[1].size(); ++j) {
a = liste[el - 1][i].first;
b = liste[1][j].first;
c = a + b;
if (c <= S) {
m[nrSecv] = m[liste[el - 1][i].second];///la nrSecv se gaseste secventa ...
m[nrSecv].push(b);
liste[el].push_back({ c, nrSecv++ });
if (c == S && el == 6) {
nrSecv--;
gasit = 1;
break;
}
}
else{
fout << -1;
return 0;
}
}
if (gasit)
break;
}
++el;
}
if (!gasit) {
fout << -1;
return 0;
}
while (!m[nrSecv].empty()) {
fout << m[nrSecv].top() << " ";
m[nrSecv].pop();
}
return 0;
}