Pagini recente » Cod sursa (job #2235616) | Cod sursa (job #440061) | Cod sursa (job #2597002) | Cod sursa (job #797708) | Cod sursa (job #2980530)
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <tuple>
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;
int n, s;
int a[NMAX];
int s3[N3MAX];
int8_t pos[N3MAX][3];
vector<int> ans;
void read() {
fin >> n >> s;
for (int i = 1; i <= n; i++)
fin >> a[i];
}
void solve() {
int cnt = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
s3[++cnt] = a[i] + a[j] + a[k];
pos[cnt][0] = i, pos[cnt][1] = j, pos[cnt][2] = k;
}
}
}
sort(s3 + 1, s3 + cnt + 1);
for (int i = 1; i <= cnt; i++) {
int p = lower_bound(s3 + 1, s3 + cnt + 1, s - s3[i]) - s3;
if (s3[p] == s - s3[i]) {
for (int j = 0; j < 3; j++) {
ans.push_back(pos[i][j]);
ans.push_back(pos[p][j]);
}
sort(ans.begin(), ans.end());
for (auto &it : ans) {
fout << a[it] << ' ';
}
return;
}
}
fout << -1;
}
int main() {
read();
solve();
return 0;
}