Pagini recente » Cod sursa (job #2826718) | Cod sursa (job #712727) | Cod sursa (job #1196364) | Cod sursa (job #1009730) | Cod sursa (job #3238056)
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream fin("loto.in");
ofstream fout("loto.out");
int n, s, a[101];
struct Triplet{
int x, y, z;
};
unordered_map <int, Triplet> sum;
int main(){
fin >> n >> s;
for(int i = 1; i <= n; i++)
fin >> a[i];
for(int i = 1; i <= n; i++){
for(int j = i; j <= n; j++){
for(int k = j; k <= n; k++){
sum[a[i] + a[j] + a[k]] = {a[i], a[j], a[k]};
}
}
}
for(int i = 1; i <= n; i++){
for(int j = i; j <= n; j++){
for(int k = j; k <= n; k++){
int dif = s - a[i] - a[j] - a[k];
if(sum.count(dif)){
Triplet t = sum[dif];
fout << a[i] << ' ' << a[j] << ' ' << a[k] << ' ' << t.x << ' ' << t.y << ' ' << t.z;
return 0;
}
}
}
}
fout << -1;
return 0;
}