Pagini recente » Cod sursa (job #1918380) | Cod sursa (job #603636) | Cod sursa (job #49146) | Cod sursa (job #2507761) | Cod sursa (job #2772109)
#include <iostream>
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream f("loto.in");
ofstream g("loto.out");
struct tuplu
{
int x,y,z;
} t;
unordered_map <int,tuplu> jum;
int main()
{
int N,S,i,j,k,a[101],s,ok=0,ok2=1;
f>>N>>S;
for(i=1; i<=N; i++)
f>>a[i];
for(i=1; i<=N; i++)
for(j=i; j<=N; j++)
for(k=j; k<=N; k++)
{
s=a[i]+a[j]+a[k];
if(S>s)
{
t.x=a[i];
t.y=a[j];
t.z=a[k];
jum[s]=t;
}
if((S>s)&&(jum.find(S-s)!=jum.end())&&ok2!=0)
{
g<<a[i]<<" "<<a[j]<<" "<<a[k]<<" ";
g<<jum[S-s].x<<" "<<jum[S-s].y<<" "<<jum[S-s].z;
ok=1;
ok2=0;
}
}
if(ok==0)
g<<"-1";
return 0;
}