Pagini recente » Cod sursa (job #1425167) | Cod sursa (job #556173) | Cod sursa (job #308298) | Cod sursa (job #1627160) | Cod sursa (job #2611163)
// By Stefan Radu
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <map>
using namespace std;
ifstream cin("loto.in");
ofstream cout("loto.out");
#define sz(x) (int)(x).size()
typedef pair < int, int > pii;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
const int MOD = 786433;
vector < vector < int > > hashMap(MOD);
bool hFind(int val) {
int hh = val % MOD;
return find(hashMap[hh].begin(), hashMap[hh].end(), val) != hashMap[hh].end();
}
void hInsert(int val) {
if (hFind(val)) return;
hashMap[val % MOD].emplace_back(val);
}
void hErase(int val) {
int hh = val % MOD;
for (int i = 0; i < sz(hashMap[hh]); ++ i) {
if (hashMap[hh][i] == val) {
swap(hashMap[hh][i], hashMap[hh].back());
hashMap[hh].pop_back();
break;
}
}
}
int main() {
#ifdef STEF
freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n, ss; cin >> n >> ss;
vector < int > v(n);
for (int i = 0; i < n; ++ i) {
cin >> v[i];
}
for (int i = 0; i < n; ++ i)
for (int j = 0; j < n; ++ j)
for (int k = 0; k < n; ++ k)
hInsert(v[i] + v[j] + v[k]);
int a = -1, b = -1;
for (const auto &v : hashMap) {
for (const int &x : v) {
if (hFind(ss - x)) {
a = x;
b = ss - x;
break;
}
}
if (a != -1) break;
}
if (a == -1) {
cout << -1 << '\n';
return 0;
}
for (int i = 0; i < n; ++ i)
for (int j = 0; j < n; ++ j)
for (int k = 0; k < n; ++ k) {
if (a != -1 and v[i] + v[j] + v[k] == a) {
cout << ' ' << v[i] << ' ' << v[j] << ' ' << v[k];
a = -1;
}
if (b != -1 and v[i] + v[j] + v[k] == b) {
cout << ' ' << v[i] << ' ' << v[j] << ' ' << v[k];
b = -1;
}
}
cout << '\n';
}