Pagini recente » Cod sursa (job #2768507) | Cod sursa (job #1833622) | Cod sursa (job #1159605) | Cod sursa (job #2715588) | Cod sursa (job #2745499)
#include <bits/stdc++.h>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
struct triplete
{
int x, y, z;
};
unordered_map <int, triplete> suma;
int main()
{
int v[101], n, s, ok = 0;
f >> n >> s;
for(int i = 0; i < n; i++)
f >> v[i];
for(int i = 0; i < n; i++)
for(int j = i; j < n; j++)
for(int k = j; k < n; k++)
suma[v[i] + v[j] + v[k]] = {v[i], v[j], v[k]}; //calculam sumele posibile
for(auto i: suma) //parcurgem map ul
if(suma.end()!= suma.find(s-i.first))//gasim "complementarul" si ne oprim
{
g << suma[s-i.first].x << " " << suma[s-i.first].y << " " << suma[s-i.first].z << " " << i.second.x << " " << i.second.y << " " << i.second.z;
ok = 1;
break;
}
if(!ok) //inseamna ca n am gasit nicio varianta
g << -1;
return 0;
}