Pagini recente » Cod sursa (job #2083657) | Cod sursa (job #217233) | Cod sursa (job #2570364) | Cod sursa (job #2258280) | Cod sursa (job #2957434)
#include <bits/stdc++.h>
using namespace std;
template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template <typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
using i64 = long long int;
const int INF = INT_MAX, MOD = 1e9 + 7;
const long long LINF = LLONG_MAX;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {0, 0, 0, -1, 1, -1, 1, 1, -1};
const int dy[] = {0, -1, 1, 0, 0, -1, 1, -1, 1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ifstream cin("loto.in");
ofstream cout("loto.out");
int N;
cin >> N;
i64 S;
cin >> S;
vector<i64> nums(N);
for (int i = 0; i < N; i++)
cin >> nums[i];
map<i64, pair<i64, i64>> sums;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) {
if (sums.find(nums[i] + nums[j] + nums[k]) == sums.end())
sums[nums[i] + nums[j] + nums[k]] = {nums[i], nums[j]};
}
}
}
vector<i64> ans;
bool done = false;
for (auto &[sum, pair]: sums) {
if (sums.find(S - sum) != sums.end()) {
ans.push_back(pair.first);
ans.push_back(pair.second);
ans.push_back(sum - pair.first - pair.second);
auto &other_pair = sums[S - sum];
ans.push_back(other_pair.first);
ans.push_back(other_pair.second);
ans.push_back(S - sum - other_pair.first - other_pair.second);
break;
}
}
if ((int) ans.size() != 0) {
sort(ans.begin(), ans.end());
for (auto x: ans)
cout << x << " ";
} else {
cout << -1 << "\n";
}
return 0;
}