Pagini recente » Istoria paginii runda/gdrgasd/clasament | Cod sursa (job #183553) | Cod sursa (job #222206) | Cod sursa (job #144480) | Cod sursa (job #2841131)
#include <iostream>
#include <unordered_map>
using namespace std;
struct pereche
{
int i = -1;
int j = -1;
int k = -1;
int sum = 0;
};
class CustomHash
{
public:
// Use sum of lengths of first and last names
// as hash function.
size_t operator()(const int &p) const
{
return p % 10007;
}
};
unordered_map<int, pereche, CustomHash> mp;
int main()
{
freopen("loto.in", "r", stdin);
freopen("loto.out", "w", stdout);
int N, S;
int nr[100];
cin >> N >> S;
for(int i = 1; i <= N; i++)
{
cin >> nr[i];
}
for(int i = 1; i <= N; i++)
for(int j = 1; j <= N; j++)
for(int k = 1; k <= N; k++)
{
pereche p;
p.i = nr[i];
p.j = nr[j];
p.k = nr[k];
p.sum = nr[i] + nr[j] + nr[k];
mp[p.sum] = p;
}
for(int i = 1; i <= N; i++)
{
for(int j = 1; j <= N; j++)
{
for(int k = 1; k <= N; k++)
{
int sum = nr[i] + nr[j] + nr[k];
int sn = S - sum;
if(mp[sn].i != -1)
{
{
cout << nr[i] << " " << nr[j] << " " << nr[k] << " ";
cout << mp[sn].i << " " << mp[sn].j << " " << mp[sn].k << " ";
return 0;
}
}
}
}
}
cout << -1;
return 0;
}