Pagini recente » Cod sursa (job #532266) | Cod sursa (job #2157384) | Cod sursa (job #3140986) | Cod sursa (job #2422815) | Cod sursa (job #2895256)
#include <iostream>
#include <unordered_map>
#include <tuple>
#include <fstream>
#include <iterator>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
int main() {
int n,s,i,suma,dif,j,z,ok=0,v[101];
f>>n>>s;
unordered_map<int, tuple<int,int,int>>M;
for(i=0;i<n;i++)
{
f>>v[i];
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
for(z=0;z<n;z++)
{
suma = v[i]+v[j]+v[z];
if(suma<=s)
{
M[suma]=make_tuple(v[i],v[j],v[z]);
}
}
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
for(z=0;z<n;z++)
{
dif = s-v[i]-v[j]-v[z];
if(M.find(dif) != M.end()){
g<<get<0>(M[dif])<<" "<<get<1>(M[dif])<<" "<<get<2>(M[dif])<<" ";
g<<v[i]<<" "<<v[j]<<" "<<v[z]<<" ";
ok=1;
break;
}
}
if(ok==1)
break;
}
if(ok==1)
break;
}
if(ok==0){
g<<-1;
}
g.close();
f.close();
return 0;
}