Pagini recente » Cod sursa (job #1320863) | Cod sursa (job #2955390) | Cod sursa (job #1113113) | Cod sursa (job #3281294) | Cod sursa (job #2696927)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
// struct punct {
// int sum, a, b, c;
// };
struct punct2 {
int a, b, c;
};
vector <int> V;
// vector <punct> A;
unordered_map<int, punct2> _map;
// bool cmp(punct x, punct y) {
// return x.sum < y.sum;
// }
// int cautBin(int x) {
// int left = -1, right = A.size();
// while (right - left > 1) {
// int mid = (left + right) >> 1;
// if (A[mid].sum < x) {
// left = mid;
// } else {
// right = mid;
// }
// }
// if (right == A.size() || A[right].sum != x) {
// return -1;
// } else {
// return right;
// }
// }
int main() {
int n, S;
fin >> n >> S;
for (int x, i = 0; i < n; ++i) {
fin >> x;
V.push_back(x);
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
int sum = V[i] + V[j] + V[k];
_map[sum] = {V[i], V[j], V[k]};
// A.push_back({sum, V[i], V[j], V[k]});
}
}
}
for (auto x : _map) {
if (_map.find(S - x.first) != _map.end()) {
fout << x.second.a << ' ' << x.second.b << ' ' << x.second.c << ' ' << _map[S - x.first].a << ' ' << _map[S - x.first].b << ' ' << _map[S - x.first].c << '\n';
return 0;
}
}
// sort(A.begin(), A.end(), cmp);
// for (int i = 0; i < A.size(); ++i) {
// int sum = A[i].sum;
// // int poz = cautBin(S - sum);
// if (poz != -1) {
// fout << A[i].a << ' ' << A[i].b << ' ' << A[i].c << ' ' << A[poz].a << ' ' << A[poz].b << ' ' << A[poz].c << '\n';
// return 0;
// }
// }
fout << -1 << '\n';
return 0;
}