Pagini recente » Cod sursa (job #802895) | Cod sursa (job #373751) | Cod sursa (job #2776061) | Cod sursa (job #968388) | Cod sursa (job #670097)
Cod sursa(job #670097)
#include<cstdio>
#include<vector>
#define infile "loto.in"
#define outfile "loto.out"
#define n_max 1005
#define MOD 666013
#define pb push_back
#define FOR(g) \
for(vector<hash> ::iterator it = g.begin(); it!=g.end(); ++it)
using namespace std;
typedef struct hash
{
int s, a, b, c;
};
vector < hash > H[MOD+5];
int a[n_max];
int N, S;
void citeste()
{
freopen(infile,"r",stdin);
scanf("%d %d", &N, &S);
for(int i=1;i<=N;i++)
scanf("%d",&a[i]);
fclose(stdin);
}
void rezolva()
{
freopen(outfile,"w",stdout);
int where, part_sum;
hash x;
for(int i=1;i<=N;i++)
for(int j=i;j<=N;j++)
for(int k=j;k<=N;k++)
if(a[i]+a[j]+a[k]<=S)
{
x.a =a[i], x.b=a[j], x.c=a[k];
x.s = a[i]+a[j]+a[k];
where = x.s % MOD;
H[where].pb(x);
part_sum = S - x.s;
where = part_sum % MOD;
FOR(H[where])
if((*it).s == part_sum)
{
printf("%d %d %d %d %d %d", (*it).a, (*it).b, (*it).c, x.a, x.b, x.c);
return;
}
}
printf("%d\n",-1);
}
int main()
{
citeste();
rezolva();
fclose(stdout);
return 0;
}