Pagini recente » Cod sursa (job #1659466) | Cod sursa (job #541267) | Cod sursa (job #1483250) | Cod sursa (job #666301) | Cod sursa (job #3129850)
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
using namespace std;
vector<int> num_cas(int n, long long sum, vector<int>& num_loto)
{
unordered_map<long long, pair<int, pair<int, int>>> suma;
/// sumele pentru triplete
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
for (int k = j; k < n; k++) {
long long total = num_loto[i] + num_loto[j] + num_loto[k];
suma[total] = make_pair(i, make_pair(j, k));
}
}
}
///vedem daca o tripleta a carei suma este scazuta din suma mare se potriveste cu cu o suma din unordered map
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
for (int k = j; k < n; k++) {
long long total = num_loto[i] + num_loto[j] + num_loto[k];
if (suma.find(sum - total) != suma.end()) {
auto p = suma[sum - total];
return {num_loto[i], num_loto[j], num_loto[k], num_loto[p.first], num_loto[p.second.first], num_loto[p.second.second]};
}
}
}
}
return {};
}
int main() {
ifstream f("loto.in");
ofstream g("loto.out");
int n;
long long s;
f>> n >> s;
vector<int> num_loto(n);
for (int i = 0; i < n; i++) {
f>> num_loto[i];
}
vector<int> nc = num_cas(n, n, num_loto);
if (nc.empty()) {
g<< "-1";
} else {
for (int i = 0; i < 6; i++) {
g<<nc[i] << " ";
}
}
return 0;
}