Pagini recente » Cod sursa (job #1755138) | Istoria paginii runda/o-n_logan | Cod sursa (job #2080294) | Cod sursa (job #1737644) | Cod sursa (job #1993943)
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cassert>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <list>
#include <functional>
#include <unordered_map>
using namespace std;
typedef long long LL;
#ifdef INFOARENA
#define ProblemName "loto"
#endif
#define MCONCAT(A, B) A B
#ifdef ProblemName
#define InFile MCONCAT(ProblemName, ".in")
#define OuFile MCONCAT(ProblemName, ".out")
#else
#define InFile "fis.in"
#define OuFile "fis.out"
#endif
#define MAXN 110
int v[MAXN], S, N;
map< int, int > M2;
map< int, int > M3;
void set3(int x, int &a, int &b, int &c) {
a = M3[x];
b = M2[x - a];
c = x - a - b;
}
void solve() {
for (const auto &it : M3) {
int needed = S - it.first;
if (!M3.count(needed)) continue;
int a, b, c;
set3(it.first, a, b, c);
printf("%d %d %d", a, b, c);
set3(needed, a, b, c);
printf(" %d %d %d\n", a, b, c);
return;
}
puts("-1");
}
int main() {
assert(freopen(InFile, "r", stdin));
assert(freopen(OuFile, "w", stdout));
scanf("%d%d", &N, &S);
for (int i = 0; i < N; ++i) {
scanf("%d", &v[i]);
for (int j = i; j >= 0; --j) {
int s = v[i] + v[j];
if (s > S) continue;
if (M2.count(s)) continue;
M2[s] = v[i];
}
}
for (int i = 0; i < N; ++i)
for (const auto &it : M2) {
int s = v[i] + it.first;
if (s > S) continue;
if (M3.count(s)) continue;
M3[s] = v[i];
}
solve();
return 0;
}