Pagini recente » Cod sursa (job #1375185) | Cod sursa (job #2924190) | Cod sursa (job #45479) | Cod sursa (job #1412628) | Cod sursa (job #2770753)
#include<iostream>
#include<fstream>
#include<unordered_map>
using namespace std;
ifstream cit("loto.in");
ofstream afis("loto.out");
struct triplu{
int x, y, z;
};
int main()
{
int N, S, nr[101], suma;
unordered_map <int, triplu> hash;
bool ok = false;
cit>>N>>S;
for(int i = 0; i < N; i++){
cit>>nr[i];
}
for(int i = 0; i < N; i++){
for(int j = i; j < N; j++){
for(int k = j; k < N; k++){
suma = nr[i] + nr[k] + nr[j];
if(S > suma){
triplu numere;
numere.x = nr[i];
numere.y = nr[j];
numere.z = nr[k];
hash[suma] = numere;
}
if(hash.find(S - suma) != hash.end()){
afis<<nr[i]<<" "<<nr[j]<<" "<<nr[k]<<" "<<hash[S - suma].x<<" "<<hash[S - suma].y<<" "<<hash[S - suma].z;
ok = true;
i = j = k = N + 1;
}
}
}
}
if(ok == false){
afis<<-1;
}
return 0;
}