Pagini recente » Cod sursa (job #3311601) | Monitorul de evaluare | Cod sursa (job #1900962) | Cod sursa (job #89601) | Cod sursa (job #3319280)
//https://www.nerdarena.ro/problema/loto1
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("fast-math")
#pragma GCC optimize ("unroll-loops")
//#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <vector>
//#include <cstring>
//#include <cmath>
//#include <bitset>
//#include <queue>
//#include <stack>
//#include <utility>
//#include <algorithm>
//#include <string>
//#include <map>
#include <unordered_map>
//#include <set>
//#include <unordered_set>
//#include <cstdint>
//#include <climits>
//#include <iomanip>
//#include <cstdio>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
constexpr const int NRMAX = 100;
constexpr const int MOD = 1 << 15;
struct Element
{
int i, j, k;
Element(int i, int j, int k) { this->i = i; this->j = j; this->k = k; }
inline bool operator==(const Element& e) const
{
return (e.i == i && e.j == j && e.k == k);
}
static const Element ZERO;
};
const Element Element::ZERO = { 0, 0, 0 };
int n, v[NRMAX + 5];
vector<pair<int, Element>> h[MOD];
void adg(int sum, int i, int j, int k)
{
int nr = sum % MOD;
Element x(i, j, k);
h[nr].push_back(make_pair(sum, x));
}
pair<int, Element> caut(int x)
{
int nr = x % MOD;
for (const auto& it : h[nr])
{
if (it.first == x)
return it;
}
return make_pair(0, Element::ZERO);
}
void generare()
{
for (int i = 1; i <= n; ++i)
{
for (int j = i; j <= n; ++j)
{
for (int k = j; k <= n; ++k)
{
int sum = v[i] + v[j] + v[k];
adg(sum, i, j, k);
}
}
}
}
int main()
{
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
int i, s;
fin >> n >> s;
for (i = 1; i <= n; ++i)
{
fin >> v[i];
}
generare();
for (int i = 0; i < MOD; ++i)
{
for (const auto& it : h[i])
{
int sum = it.first;
int a1 = it.second.i;
int b1 = it.second.j;
int c1 = it.second.k;
if (s - sum <= 0)
continue;
pair<int, Element> nr = caut(s - sum);
if (nr != make_pair(0, Element::ZERO))
{
int a2 = nr.second.i;
int b2 = nr.second.j;
int c2 = nr.second.k;
fout << v[a1] << " ";
fout << v[b1] << " ";
fout << v[c1] << " ";
fout << v[a2] << " ";
fout << v[b2] << " ";
fout << v[c2] << " ";
return 0;
}
}
}
fout << -1;
return 0;
}