Pagini recente » Cod sursa (job #2476446) | Cod sursa (job #1198439) | Cod sursa (job #1718544) | Cod sursa (job #2487166) | Cod sursa (job #2980543)
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#ifdef LOCAL
ifstream fin("input.txt");
#define fout cout
#else
ifstream fin("loto.in");
ofstream fout("loto.out");
#define endl '\n'
#endif
const int NMAX = 105;
const int N3MAX = NMAX * NMAX * NMAX;
struct piii {
int8_t i, j, k;
};
int n, s;
int a[NMAX];
pair<int, piii> s3[N3MAX];
bool cmp1(const pair<int, piii> &a, const pair<int, piii> &b) {
return a.first < b.first;
}
bool cmp2(const pair<int, piii> &a, const int &b) {
return a.first < b;
}
void read() {
fin >> n >> s;
for (int i = 1; i <= n; i++)
fin >> a[i];
}
void solve() {
int cnt = 0;
for (int8_t i = 1; i <= n; i++) {
for (int8_t j = 1; j <= n; j++) {
for (int8_t k = 1; k <= n; k++) {
s3[++cnt].first = a[i] + a[j] + a[k];
s3[cnt].second = {i, j, k};
}
}
}
sort(s3 + 1, s3 + cnt + 1, cmp1);
for (int i = 1; i <= cnt; i++) {
int p = lower_bound(s3 + 1, s3 + cnt + 1, s - s3[i].first, cmp2) - s3;
if (s3[p].first == s - s3[i].first) {
vector<int8_t> ans = { s3[p].second.i, s3[p].second.j, s3[p].second.k, s3[i].second.i, s3[i].second.j, s3[i].second.k };
sort(ans.begin(), ans.end());
for (auto &it : ans) {
fout << a[it] << ' ';
}
return;
}
}
fout << -1;
}
int main() {
read();
solve();
return 0;
}