Pagini recente » Cod sursa (job #1265109) | Cod sursa (job #274185) | Cod sursa (job #29704) | Cod sursa (job #274187) | Cod sursa (job #2747310)
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
int n, s;
int v[110];
unordered_map <int,pair<int,pair<int,int>>> mapa;
int main(){
ifstream in("loto.in");
ofstream out("loto.out");
in >> n >> s;
for(int i = 1; i <= n; i++)
in >> v[i];
for(int i = 1; i <= n; i++)
for(int j = i; j <= n; j++)
for(int k = j; k <= n; k++)
mapa[v[i] + v[j] + v[k]] = make_pair(i, make_pair(j, k));//create has table
for(int i = 1; i <= n; i++)
for(int j = i; j <= n; j++)
for(int k = j; k <= n; k++){
int total = v[i] + v[j] + v[k];
if(mapa.count(s - suma)){
out << v[i] << " ";
out << v[j] << " ";
out << v[k] << " ";
out << v[mapa[s - total].first] << " ";
out << v[mapa[s - total].second.first] << " ";
out << v[mapa[s - total].second.second];
return 0;
}
}
out << "-1";
return 0;
}